Multithreading trick needed

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

Dear all,
Is there some trick to put controls on a particular control but in other
thread.
Example:
A control is a part of bigger application and application thread freezes
somtimes. So a control freezes too. What I need is to spawn a thread and put
controls main thread in this thread.
Is it possible?
Thanks,
Boni
 
Hi Boni

Not exactly what you were asking, but I would consider what is causing the
main thread to freeze, and look at putting that process onto another thread.
That way the main thread, and hence your controls remain responsive. It
could be much easier to do as well.

HTH

Charles
 
Boni,

For this what you build is in VS2005 now the background worker.

Just to give the idea

Cor
 
Hi, Boni,
Having any UI (forms, controls or whatever) run on a thread other than the main foreground thread is generally Not A Good Thing To Do. It creates a host of headaches (race conditions, contentions, etc.) when trying to gain access to the various window resources available. It's far better to track down end eliminate whatever's causing the freeze-up.

That being said, there are certainly good uses for worker threads, and they can be leveraged to make your UI more responsive. I use them to take care of the number-crunching which doesn't impact the UI directly. So, for example, a user might click on a control and choose to do something performance intensive. What I do then it to disable the control after the click, spawn a thread and allow it to do the busy work, and when I'm informed that the thread has exited (via callback or message, whatever you like), I reenable the control and display whatever information is required. In the meantime, other controls can still be interacted with -- they're not frozen. I just need to be careful that nothing that those other controls do impacts any resources which that background thread requires. (Visual Studio itself works this way -- compilation, for example, occurs in a background thread so that you can still interact with the UI -- notably, "Cancel" among other things. The controls are still on the main thread; it's just the processing which is not.

The following link provides a general threading example:
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconcreatingthreads.asp.

Hope this helps,

--Matt Gertz--*
VB Compiler Dev Lead


-----Original Message-----
From: Boni
Posted At: Tuesday, November 15, 2005 10:07 AM
Posted To: microsoft.public.dotnet.languages.vb
Conversation: Multithreading trick needed
Subject: Multithreading trick needed


Dear all,
Is there some trick to put controls on a particular control but in other
thread.
Example:
A control is a part of bigger application and application thread freezes
somtimes. So a control freezes too. What I need is to spawn a thread and put
controls main thread in this thread.
Is it possible?
Thanks,
Boni
 

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

Back
Top