469,364 Members | 2,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

UserControl always run in seperate thread

Joe
I need a control to always run in a separate thread from the application.
I'm not too sure where to begin with this since the control could be dropped
on the form at design time.

One possible idea I had was to wrap my control in another control which
creates the thread and than creates the control.

Any suggestions?

-Joe
Jan 16 '06 #1
7 10050
This is not my strongest area in .NET but I don't think this would
work.

(Most) controls aren't thread safe and the UI thread would be calling
methods on your control (e.g. Paint, because you've added it to the
main forms control collection) even though you created the control on
your own different thread.

I maybe wrong and I'd be very interested to hear a solution.

You might want to try posting to winforms newsgroup.

Josh
http://www.thejoyofcode.com/

Jan 16 '06 #2
Actually - it might have been wiser of me to ask "Why do you need your
control to run in a different thread?".

If it's because you want to *update* your control from a different
thread, then this is easy to do using the Invoke method on the control
(or form):
http://msdn.microsoft.com/library/en...asp?frame=true

Jan 16 '06 #3
Joe
Hi Josh,

Actually, all the control does is display a spinning wheel (like in SQL
2005) when something is happening which will take a while - sort of like a
progress bar and displays a message like Please wait...

I was thinking about calling BeginInvoke but I would need something to
prevent it from returning until I'm done.

I guess the only other idea is to make all the work happen on another
thread.

-Joe

"Josh Twist" <jo********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Actually - it might have been wiser of me to ask "Why do you need your
control to run in a different thread?".

If it's because you want to *update* your control from a different
thread, then this is easy to do using the Invoke method on the control
(or form):
http://msdn.microsoft.com/library/en...asp?frame=true

Jan 16 '06 #4

"Joe" <jb*******@noemail.noemail> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
| Hi Josh,
|
| Actually, all the control does is display a spinning wheel (like in SQL
| 2005) when something is happening which will take a while - sort of like a
| progress bar and displays a message like Please wait...
|

That 'something' should be done on a separate background thread, the
updating of the UI (your spinning wheel) should be done using
Control.BeginInvoke or Control.Invoke.

Willy.
Jan 16 '06 #5
Joe
Hi Willy,

The problem is the spinning wheel is just an animated GIF. I want to show my
UserControl in a panel (which is in the main thread) and allow the GIF to
remain animated.

I'm not sure how to use BeginInvoke to work in this case.

-Joe

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uA**************@TK2MSFTNGP14.phx.gbl...

"Joe" <jb*******@noemail.noemail> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
| Hi Josh,
|
| Actually, all the control does is display a spinning wheel (like in SQL
| 2005) when something is happening which will take a while - sort of like
a
| progress bar and displays a message like Please wait...
|

That 'something' should be done on a separate background thread, the
updating of the UI (your spinning wheel) should be done using
Control.BeginInvoke or Control.Invoke.

Willy.

Jan 16 '06 #6
Joe <jb*******@noemail.noemail> wrote:
Actually, all the control does is display a spinning wheel (like in SQL
2005) when something is happening which will take a while - sort of like a
progress bar and displays a message like Please wait...

I was thinking about calling BeginInvoke but I would need something to
prevent it from returning until I'm done.

I guess the only other idea is to make all the work happen on another
thread.


See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #7
Hi Joe,

I agree with Willy on using background thread together with using the
Control.Invoke method....
Actually the controls you're using are someones which display the waiting
UI and message, yes? I think we can just define some method in the Form
class which used to control the UI (updating the control's states....),
then since our long run task are being processed in background thread and
we should not directly call those Form's method to update UI, so we can use
Control(Form).Invoke method to call those method to update UI in the
background thread's thread function..... e.g:

suppose our backgroun thread do the following function:

while (xxxxxx)
{

//do the work....

_form.Invoke(UpdateUIFunction_Delegate......);
}

UpdateUIFunction_Delegate just wrapper a Form's member function which
update some of the controls on the form(maybe your GIF components or....)

Some other related reference articles:

$Give Your .NET-based Application a Fast and Responsive UI with Multiple
Threads
http://msdn.microsoft.com/msdnmag/is...ultithreading/

#Making a Rich Client Smart : Using Multiple Threads
http://blogs.msdn.com/dphill/archive...12/183503.aspx
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Joe" <jb*******@noemail.noemail>
| References: <e1**************@TK2MSFTNGP10.phx.gbl>
<11**********************@g47g2000cwa.googlegroups .com>
<11**********************@g44g2000cwa.googlegroups .com>
<u7**************@TK2MSFTNGP10.phx.gbl>
<uA**************@TK2MSFTNGP14.phx.gbl>
| Subject: Re: UserControl always run in seperate thread
| Date: Mon, 16 Jan 2006 16:37:05 -0500
| Lines: 32
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <uh**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 69.37.58.70.adsl.snet.net 69.37.58.70
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.languages.csharp:378903
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Willy,
|
| The problem is the spinning wheel is just an animated GIF. I want to show
my
| UserControl in a panel (which is in the main thread) and allow the GIF to
| remain animated.
|
| I'm not sure how to use BeginInvoke to work in this case.
|
| -Joe
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:uA**************@TK2MSFTNGP14.phx.gbl...
| >
| > "Joe" <jb*******@noemail.noemail> wrote in message
| > news:u7**************@TK2MSFTNGP10.phx.gbl...
| > | Hi Josh,
| > |
| > | Actually, all the control does is display a spinning wheel (like in
SQL
| > | 2005) when something is happening which will take a while - sort of
like
| > a
| > | progress bar and displays a message like Please wait...
| > |
| >
| > That 'something' should be done on a separate background thread, the
| > updating of the UI (your spinning wheel) should be done using
| > Control.BeginInvoke or Control.Invoke.
| >
| > Willy.
| >
| >
|
|
|

Jan 17 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Lokhan Wong | last post: by
2 posts views Thread by Cederstrom | last post: by
12 posts views Thread by Joe | last post: by
9 posts views Thread by Marcelo Cabrera | last post: by
5 posts views Thread by RobKinney1 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.