How to inform Parent thread from a Child Thread?

  • Thread starter Thread starter Dinesh Jain
  • Start date Start date
D

Dinesh Jain

Hi all,
How to inform Parent thread from a Child Thread?
I mean want to notify something from Child thread to
Parent Thread.

Please help,
Thanks in advance,

-Regards,
Dinesh
 
Hi Dinish,

You can set a public event in a child thread that you can catch in a Parent
thread.

This is decribed in the walkthroughs for multithreading in/on MSDN

I hope this helps a little bit?

Cor
 
Hi Cor,
Thanks for the reply.
Can you specify the link on where can I find the Walkthrough on MSDN
for threading?

Thanks in advance,

-Regards,
Dinesh
 
Hi Cor,
Thanks for the link. I have gone through some of the
subtopics.
Let me be specific about my problem-
I have a form which I am creating by calling "new"
from main thread. Then I am creating a subthread in which
I am accessing that form inside the subthread.
At some moment, I want to again call the "New" of that
form from the subthread. But I want that the New should be called by
Main thread.

How can I inform Main thread from my Sub thread about
to create new instance of that form?

Will Control.Invoke solve this problem?

Please help,
Thanks in advance,

-Regards,
Dinesh
 
Hi Dinish,

You cannot reach a thread but from the thread you can reach a static
variable in your application.

I give you again a link, it is very few information, but I think with that
you have the solution.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmSyncLock.asp

Cor

Did you see this anouncement in this newsgroup.

I never know at what time it is, because they only give the times for
British and US people and a timetable accoording to GMT time but no GMT
time. Although I believe there is no BST time now also. It is almost
Christmass and that is not in summer in Britain.
----------------------------------------------------------------------------
-----------
Do you have questions about how to create multi-threaded applications? Or do
you wonder about what those threads are actually doing? Then join members of
the Visual Basic and .NET Framework teams as they answer your questions
about using threading with Visual Basic .NET.

Date:
November 25, 2003

Time:
1:00 - 2:00 P.M. Pacific time
4:00 - 5:00 P.M. Eastern time
21:00 - 22:00 BST/BST
(For a list of local time zones relative to GMT, please see
http://msdn.microsoft.com/chats/timezones.asp.)

Outlook Reminder:
http://msdn.microsoft.com/chats/outlook_reminders/VB_Nov25.vcs

Location:
http://msdn.microsoft.com/chats (then click the name of the chat to enter
the chat room)

For more information about Visual Basic .NET, see
http://msdn.microsoft.com/vbasic/
To see a list of upcoming chats or set a reminder for this chat, see
http://msdn.microsoft.com/chats.
For archives of previous chats, see
http://msdn.microsoft.com/chats/recent.asp.

Thanks!
Jason Cooke
VB.NET Team
========
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
(c) 2003 Microsoft Corporation. All rights reserved.
 
Dinesh,
How can I inform Main thread from my Sub thread about
to create new instance of that form?

Will Control.Invoke solve this problem?
Yes if you are attempting to notify a Form or other control, Control.Invoke
is the "best" way to go. You may need a separate hidden form, unless you
have a known main form, that your background thread can Control.Invoke on to
cause the new form to be created.

If you are attempting to notify a background thread from a Form. I normally
create a System.Collection.Queue object to hold the info I want to send, the
Form will enqueue requests onto the queue, the background will Dequeue
Requests from the queue. Of course you need to be certain to use Synclock to
ensure only one thread is modifying the queue at a time. Also I will use a
System.Threading.AutoResetEvent to notify the background thread that a new
item has appeared on the queue... Which means that when the background
thread is not processing a request it is waiting for an item on the queue,
the AutoResetEvent allows the background thread to go to sleep until an item
appears on the queue. This queue technique generally complicates your main
thread, hence its "better" to use a Form & Control.Invoke on your main
thread.

Hope this helps
Jay
 
Back
Top