multiple threads with a form

G

Guest

Hi,

I have a form in main thread. I also use a 2nd thread as datalayer for
dataset <--> SQL Server. I have some controls that binds with the dataset.

When the 2nd thread modifies the dataset, it will trigger events of a
control that binds to the dataset. My question is if the event run on the 2nd
thread or the main thread?

When I step in, I check Me.InvokeRequired and it's True. Does that mean the
event run on the 2nd (background) thread?

Thanks in advance.

Li
 
K

Kevin Spencer

The event runs on the 2nd thread. A Windows form is a Single-Threaded
Apartment. If you're working with .Net platform 2.0, you might want to check
out the BackgroundWorker component:

http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

Otherwise, here are a few articles that will help even if a BackgroundWorker
is not available:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
 
G

Guest

Thanks a lot! Kevin.

Li


Kevin Spencer said:
The event runs on the 2nd thread. A Windows form is a Single-Threaded
Apartment. If you're working with .Net platform 2.0, you might want to check
out the BackgroundWorker component:

http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

Otherwise, here are a few articles that will help even if a BackgroundWorker
is not available:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top