473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 10408
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Serge | last post by:
Hi, I have some intensive code that is running on my main thread. I try to show a status update on a 'status form'. The problem that i have is that because it is running in the same thread the...
2
by: Lokhan Wong | last post by:
My question is whether it's possible to change the properties of a panel, that resides on the webform containing the usercontrol, in the usercontrol itself. Like this: <form> <asp:panel...
2
by: Cederstrom | last post by:
Hello Group, I have created an ASP.NET page. The page consist of the following items: - Button A - Button B - UserControl When I press Button A, I execute the following code: ViewState =...
7
by: Kristoffer Arfvidson | last post by:
HI! I have a little question... I need to access a usercontrol (*.ascx) file that is located outside my application directory of my dll... Heres my paths on my server: wwwroot/ --------------...
3
by: jesper_lofgren | last post by:
Hi, I have two usercontrols one menu control that use ASP.NET 2.0 Treeview control, then a main usercontrol for showing the selected URL in a Iframe. The problem is when i raise the...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
5
by: RobKinney1 | last post by:
Wow... unbelieveable that this problem would arise right before giving the software to our public testers... or maybe it is believable. We tweaked some seemingly unrelated code somewhere else...
0
by: luckilian | last post by:
Hi everyone, i need some help with a tabbed interface. I have this scenario: 1 Main Form 1 UserControl 1 Form when main form is loaded the Usercontrol load .. In the _load handler i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.