473,698 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10432
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********@gma il.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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*******@noem ail.noemail> wrote in message
news:u7******** ******@TK2MSFTN GP10.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.BeginIn voke 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******** ******@TK2MSFTN GP14.phx.gbl...

"Joe" <jb*******@noem ail.noemail> wrote in message
news:u7******** ******@TK2MSFTN GP10.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.BeginIn voke or Control.Invoke.

Willy.

Jan 16 '06 #6
Joe <jb*******@noem ail.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.co m>
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).I nvoke 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(Up dateUIFunction_ Delegate......) ;
}

UpdateUIFunctio n_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*******@noem ail.noemail>
| References: <e1************ **@TK2MSFTNGP10 .phx.gbl>
<11************ **********@g47g 2000cwa.googleg roups.com>
<11************ **********@g44g 2000cwa.googleg roups.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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 69.37.58.70.ads l.snet.net 69.37.58.70
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.langua ges.csharp:3789 03
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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******** ******@TK2MSFTN GP14.phx.gbl...
| >
| > "Joe" <jb*******@noem ail.noemail> wrote in message
| > news:u7******** ******@TK2MSFTN GP10.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.BeginIn voke 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
3319
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 window is not responding to the user. The user is now able to minimize, move the window because the code is too busy on it's own work. (and they are all running on the same thread)
2
1806
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 visibility=false .... </asp panel> <user:control> //a function here turns the visibilty to true </user:control>
2
1350
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 = "edit"; Session = "edit";
7
1248
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/ -------------- /index.aspx /controls/menu.ascx
3
2399
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 OnSelectedNodeChanged on the menu and add the URL value into a session or Viewstate key and collect the value on the second (main usercontrol) the value is always i step behind the actual click value ?
12
2204
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 server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
9
14450
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 does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing...
5
5629
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 having nothing to to with this object, and now the following function is causing a System.StackOverflowException: private void ResetAllDataFieldsSafely() { if(myWebBrowser.InvokeRequired) //always evaluates to true
0
1098
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 want to open then Form in separate thread
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.