473,811 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Winforms and threads

I know that the controls on a Winform are not thread safe, and that you want
to do all of your UI updates on a single thread -- generally the main
thread.

Now, 2 questions:
1. Does the one thread that you can use to update controls have to be the
thread that you were on when you instanced the form?

2. Can 2 forms in the same application have affinity for different threads,
or do you want all of the forms in an application to be created on the main
thread?

Why I'm asking:

I'm working on a module that will place an item in system tray. The code
associated with the tray item will use a secondary thread to listen for
system events, and based on some of the events, it might have to launch a
form. Do I need to work in some logic to make sure that the form launch
code is always executed by the main thread?
Nov 15 '05
10 2785
Hmm.

I think I'm finished here, you've clearly hit a point where you cannot
logically argue, so you're throwing out a few one-liners.

I can't help but to point out that your initial argument was "just do what
works for you", and now you are attempting to back that up by suggesting
that I go read about what other people are doing.
Hmm.

But beyond that, I would love to hear your explanation of exactly what you
think these newsgroups are for.

Personally, I use them as a resource for seeking answers to general
questions, so that I can tune my research, and as airing platform so that I
can get reality checks on technical and design decisions, and as an
opportunity to poll the experience of other professionals when I feel it
appropriate.

I also try to repay the community by providing constructive, helpful
responses when I encounter someone with a problem that I am familiar with.
Oh, and since I do pay for MSDN Universal, which includes newsgroup support,
I feel completely entitled to post a question when one arises.

"Alvin Bruney" <al**********@t elia.com> wrote in message
news:OS******** *****@TK2MSFTNG P11.phx.gbl...
Its called MSDN, go read it.
"J.Marsch" <je****@ctcdeve loper.com> wrote in message
news:Oy******** ******@TK2MSFTN GP10.phx.gbl...
Well, with all due respect (though you've shown me none). What works for
me
may not work for Windows. If I'm about to make a design decision that will
affect the architecture of a UI layer that will be used in multiple
applications, and as the basis for the design of hundreds of forms, don't you sort of think that it would be a good idea to make sure that the
threading model is compatible with the Windows UI layer???

That's called called due dilligence and common sense, Alvin.

If you don't have anything useful to add to this conversation, why don't you just crawl back under whatever rock you came out from under.

"Alvin Bruney" <al**********@t elia.com> wrote in message
news:eX******** ******@TK2MSFTN GP10.phx.gbl...
Do what works for you. Why Must you follow everybody else when you're
solution is for you.

If I told you to shove yer hand in the oven , would you? Or cut on yer
gonads?

"J.Marsch" <je****@ctcdeve loper.com> wrote in message
news:#w******** ******@TK2MSFTN GP12.phx.gbl...
> Thank you all for your input, but there's a fine point here that I'm
trying
> to close in on. We are on the same page regarding Invoke and that the > "owning" thread must fire events on the control, and I agree that this is
a
> Windows issue, not winforms.
>
> What I'm lost on:
> What would be best practice for instancing a form? In my example, a
> background thread will possibly need to throw up a form in response
to a > system event. When that happens, from a best-practice point of
view,
am
I
> ok just instancing a form on the spot, or am I better off creating a
pattern
> that will cause the form to be created on the application's Main thread? >
> ""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in
message > news:ub******** ******@cpmsftng xa07.phx.gbl...
> >
> > Hi,
> >
> > In winform, controls in Windows Forms are bound to a specific thread and
> > are not thread safe.
> > There are four methods on a control that are safe to call from any
thread:
> > Invoke, BeginInvoke, EndInvoke and CreateGraphics. For all other method
> > calls, you should use one of these invoke methods when calling

from a > > different thread.
> >
> > The sample below tells you how to manipulate multithreading
winform > > controls:
> >
>

http://msdn.microsoft.com/library/de...us/cpguide/htm
> > l/cpconDeveloping MultithreadedWi ndowsFormsContr ol.asp
> >
> > Hope this helps,
> > Best regards,
> > Jeffrey Tan
> > Microsoft Online Partner Support
> > Get Secure! - www.microsoft.com/security
> > This posting is provided "as is" with no warranties and confers no
rights.
> >
>
>



Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
5631
by: David Noble | last post by:
We've been developing a web site using 3-tier architecture for 18 months now. There is a common layer that defines the classes - using XML schemas. The data layer acts as a wrapper to 3 databases - SQL Server, Oracle and AS400. The business layer exposes web services which communicate with the front end, ASP.Net. All 3 tiers are on different boxes. This works well. Now I am leading a team to build a winforms app. I need some advice as
2
2084
by: Steve Smith | last post by:
I have written an application that launches approximately 150 threads with Thread.ThreadStart() Each thread uses CDO 1.21 to logon to a different Exchange mailbox and send/receive a number of mail messages, reporting back to the UI thread through the use of a Queue object. When all messages that are expected have been received, each thread sends a final update to the UI and the method should exit, which should terminate the thread. ...
11
2219
by: Steve Smith | last post by:
I have written a winforms application that launches approximately 150 threads with Thread.ThreadStart() Each thread uses CDO 1.21 to logon to a different Exchange mailbox and send/receive a number of mail messages, reporting back to the UI thread through the use of a Queue object. When all messages that are expected have been received, each thread sends a final update to the UI and the method should exit, which should terminate the...
8
13599
by: vdahiya | last post by:
Hi All, I am using winform threads and I have craeted a new thread to perform soem lengthy operations asynchronously. My problem is that while this operation is being performed i am updating the window status bar to display the status of the operation. But as soon as the window loses the focus it freezes (mean the staus bar is not updated anymore). following is my code (in UI thread):
5
3831
by: brian.wilson4 | last post by:
Our group is currently comparing winforms vs webforms.....app is Corp LAN based - we have control of desktops.....Below is pros and cons list we have come up with - if anything strikes you as untrue or you would like to add - please comment - thanks..... Rich Client PROS 1. User experience (* indicates feasible on web with AJAX) - a. Single, unified application experience b. Windows/Office-like look and feel - i.Tabs - drag and drop...
3
1561
by: D. Patrick | last post by:
I need to guide the training for some good ASP.NET programmers who don't have Windows Forms experience, and they will soon be put onto a project for multi-threaded winforms development. Can anyone suggest a good book for multi-threaded winforms learning? Or even some good URLs?
5
3278
by: Peted | last post by:
Just some threading questions 1. in a MDI app if you have multiple child forms, does each child form run in its own thread ? Eg do you get error trying to update one control on form1 from form 2 2. if you have a timer control running on a childform, and you either a. minimize or
3
4683
by: =?Utf-8?B?Y2hlbmRyaWNrcw==?= | last post by:
I have a C# winforms application that makes periodic web service calls in background thread to my web service server. These calls work fine almost all the time but on rare occassions the web service method call will never return and the entire application will freeze, even though the call is being made on its own background thread, not the main UI thread. Does anyone know any reason why a particular web service method call would cause my...
4
6356
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
Visual Studio 2005, C# WinForms application: Here’s the question: How can I increase the standard 1 MB stack size of the UI thread in a C# WinForms application? Here’s why I ask: I’ve inherited some code that at the view (User Interface) layer kicks off a background worker thread. At the service layer (think CAB service layer), there’s quite a lot of the following:
0
9728
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
9605
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
10648
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...
0
10389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10402
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
7670
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
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3867
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.