is this the right way to do multithreading

I derive an object from a Form and instantiate it like this

//sc is the instance of an object derived from Form

                        Thread t = new Thread(() =>
                        {
                            IntPtr dummy = sc.Handle;
//above statement creates the window

                            Application.Run();
                        });

then when I want to call a method of sc from the other thread I do

 sc.BeginInvoke (....);

thanks
0
alexl
11/17/2009 2:18:40 AM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

2 Replies
1104 Views

Similar Articles

[PageSpeed] 31

alexl wrote:
> I derive an object from a Form and instantiate it like this
> 
> //sc is the instance of an object derived from Form
> 
>                         Thread t = new Thread(() =>
>                         {
>                             IntPtr dummy = sc.Handle;
> //above statement creates the window
> 
>                             Application.Run();
>                         });
> 
> then when I want to call a method of sc from the other thread I do
> 
>  sc.BeginInvoke (....);

You can do it that way.  But there's nothing in your question that 
suggests that you _should_ do it that way.

Typically, you would just use the main thread that already is created 
for a Forms application as the owner thread for all GUI objects (e.g. 
Form subclasses).  Then non-GUI code can execute on other threads, using 
Control.Invoke() or Control.BeginInvoke() to access the GUI objects.

The code snippet you posted will create a new thread, force the creation 
of the Form subclass's window handle in the new thread, and then start a 
message pump loop to handle messages in that thread.  But a) for that 
code to work, you have to be very careful that the Form subclass's 
window handle isn't created earlier, and b) it's unclear what benefit 
you expect to get by forcing the Form subclass to be owned by a new 
thread rather than the one that would normally be used.

Pete
0
Peter
11/17/2009 2:41:40 AM
thanks for your  answer.

> it's unclear what benefit
> you expect to get by forcing the Form subclass to be owned by a new
> thread rather than the one that would normally be used.

I am using a sdk that uses COM so I thought I have to keep its thread
separate. The sdk in question is UCCApi. thanks
0
alexl
11/17/2009 3:07:07 AM
Reply:

Similar Artilces:

Scrolling Left to Right in Excel using mouse scroll.
This is the first time I've seen this, a user has a worksheet that scrolls left to right when using the mouse scroll. Every other sheet moves up and down like I've always seen. Anyway any help would be appreciated, sorry for the dumb question. ...

Help, I moved mailboxes and now can open boxes using "Service account admin" rights
Hey everyone, We are running a Windows 2003 domain and Exchange 2003 sp1 on Win2k3 in a cluster. We had ONE storage group and 4 DBs. I have a AD group that has Exchange "Service account admin" rights and people in that group could open ANY mailbox. I am in that group too. Over the weekend we created a NEW storage group in Exchange and MOVED tow DBs from SG1 to SG2 (the new SG). Now I can't open anyone's mailbox that is in the new SG. The users are working fine. They can connect to their mailboxes using Outlook 2003 just fine. However, I am troubleshooting a Bl...

exchange tools listed twice in ADUC right click
We installed exchange but forgot to install the tools option so we did it after. When that happened it locked up with errors part of the way thru. When I restarted after a system reboot and installed them again it now listed in the active directory users and computers extensions twice when you right click on an object. I removed the tools, it removes both entries. I reinstalled and now both entries are back. Where can I find these entries in AD and remove the duplicate. Thanks Comments inline below. -- Ed Crowley MVP "There are seldom good technological solutio...

Lost Properties pop up on right mouse click?
Hi, I can no longer right click on a control and bring up its properties. I have to be in design mode and select the field then click the properties button in the tool bar? Any idea how to get the right mouse click to bring the properties up? Thanks Chuck "Chuck" <Chuck@discussions.microsoft.com> wrote in message news:00FD3588-E880-498C-9F24-8E4D6A8F464B@microsoft.com... > Hi, I can no longer right click on a control and bring up its properties. > I > have to be in design mode and select the field then click the properties > button in the tool bar? > Any ide...

Is there a way to do this without cursors?
/* All rows in #T1 for the same HId and with the same Priority should be combined into a single row in #T2. When creating a merged row, the Events column in #T2 should be a concatenation of all of the events of the distinct (HId, Priority) that were merged. */ _____________________________ DDL: _____________________________ CREATE TABLE #T1 ( HId int not null, Priority tinyint not null, [Event] varchar(30) Not Null, constraint [PKT1] primary key clustered ( HId ASC, Priority ASC, [Event] ASC ) ) GO insert into #T1 select 1,5,'C' union select 1,5,&...

an easy way..to earn...in a momemt,
Dear all, I recently joined AGLOCO because of a friend recommended it to me. I am now promoting it to you because I like the idea and I want you to share in what I think will be an exciting new Internet concept. AGLOCO's story is simple: Do you realize how valuable you are? Advertisers, search providers and online retailers are paying billions to reach you while you surf. How much of that money are you making? NONE! AGLOCO thinks you deserve a piece of the action. AGLOCO collects money from those companies on behalf of its members. (For example, Google currently pays AOL 10 cent...

Textbox (Object) Right Click Menu
I am looking to disable the right click Cut event when dealing with Text boxes (Drawing Objects). I have seen code that disables the right click cut. The following code works on the page, but not when a textbox is selected: Dim TheCmdBar as Office.CommandBarControl for each TheCmdBar in Applicaiton.CommandBars.FindControls(ID:=21) TheCmdBar.Enabled = False Next TheCmdBar Thanks in advance. ...

Is there a way to know when a Contact Record was created?
Is there a way or place to see when a Contact Record was created? I used to us ACT and part of the Properties or General Info automatically recorded the Creation Date for that Contact. It was very useful info to purge my Data Base of Old Inquiries that never developed. "WIM4246" <WIM4246@discussions.microsoft.com> wrote in message news:93299CA1-AD1A-421D-8371-97DF1AE6BB03@microsoft.com... > Is there a way or place to see when a Contact Record was created? > > I used to us ACT and part of the Properties or General Info automatically > recorded th...

Is there any easy way to export EX2003 server GAL to Excel?
Is there a utility that can enable an administrator to cleanly export the entire Global Address List from and Exchange 2003 Server, into Excel (or a comma or tab delimited file format) without having to jump through too many hoops? It's easy to do from MS Access. Start with a blank database and then go to the file menu and choose External Data. Select the type as Outlook and select the GAL. Once You've got a link you can then view the data and even use the Tools | Office links menu and select Analyze with Excel. -GT "Robert Gordon" <rgordon@nospam.visto.com>...

Can't right-click in excel
I have a user that showed me the most interesting issue. She is unable to right-click while using Excel. In any other program or even on the desktop she can righ-click and bring up the appropriate right-click menu. But in excel this does not work. is there a setting in Excel that might be causing this problem? -- macquarl ------------------------------------------------------------------------ macquarl's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26388 View this thread: http://www.excelforum.com/showthread.php?threadid=468070 Hi Macquarl, Try this com...

Easy way to find a link?
Is there a quick easy way to find a link in a workbook that has 50 pages? The best is to use the LINK feature in Excel and if necessary to combine it with the FIND REPLACE tool. To see how to do this you can go to http://www.auditexcel.co.za/othertools.html and watch the video clips for External Links and Find Replace. Hope that helps "LSchmitz" wrote: > Is there a quick easy way to find a link in a workbook that has 50 pages? > > > Is it a link to another workbook? If yes, then I'd use Bill Manville's FindLink program: http://www.oaltd.co.uk/MVP/Defa...

Right Click Context Menu
Is there a way to add items to the list? -- Guy Lapierre Forefront Business Solutions http://www.forefrontbusinesssolutions.com Guy Using VBA only. Check out this google search thread. Many good ideas for code and methods of implementing. http://snipurl.com/dr42 Gord Dibben Excel MVP On Tue, 29 Mar 2005 14:52:10 GMT, "Guy Lapierre" <guy@forefrontbusinesssolutions.com> wrote: >Is there a way to add items to the list? ...

Enums, Combobox, Best Way to List and Select
Is there a simply way to list Enum choices in a combobox and then use the selection? "David" <dw85745NOT@earthlink.net> wrote in message news:uEwiq2xgKHA.5528@TK2MSFTNGP05.phx.gbl... > Is there a simply way to list Enum choices in a combobox and > then use the selection? Yes, and it involves Excel or similar spreadsheet program. See this post for details: http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/1f9b4717253fd3e4 "Nobody" <nobody@nobody.com> wrote in message news:eFOJNjygKHA.4872@TK2MSFTNGP05...

How to dock the second and third toolbars to the right corner of the first toolbar using mfc or win32?
Hi, I have created a main toolbar, and two more toolbars. All three are aligned at TOP, one below the other. I use DockControlBar to dock them. m_ToolBar1.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM); m_ToolBar2.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM); m_ToolBar3.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_ToolBar1); DockControlBar(&m_ToolBar2); DockControlBar(&m_ToolBar3); It was all fine till this point. The problem comes next. Now, I need to have them all in a single line. It should look someth...

Is there a way to make Excel 2000 open a new worksheet in a new w.
Is there a way to make Excel open a new worksheet in a new window Hi 'Tools - options - View' and check 'Windows ins taskbar' -- Regards Frank Kabel Frankfurt, Germany gdub wrote: > Is there a way to make Excel open a new worksheet in a new window ...

What is the right syntax for vlookup in vba?
Hi, Using Excel 2000, the code is returning an error--"runtime error. Type mismatch" on this line: Me.txt1.Text = Application.Evaluate("=VLookup(" & sCoreAdapShell & ", tblPriceListCorePart, 5,False)") I'm looking for feedback about the syntax for using vlookup in vba. The above line is in the commandbutton--cmdCalc with the following code: Private Sub cmdCalc_Click() Dim sCoreAdapShell As Variant sCoreAdapShell = txtCore.Text & txtAdap_Config.Text & txtShell.Text Me.txt1.Text = Application.Evaluate("=VLookup(" &a...

Quick way for removing manual pagebreaks
Hi, Is there a quicker way to remove the manual pagebreaks than the way below? If ActiveCell.Rows.PageBreak = xlPageBreakManual Then ActiveCell.PageBreak = xlNone End If Thanks in advance Paul ActiveSheet.ResetAllPageBreaks -- Jim Rech Excel MVP Jim thank you very much. "Jim Rech" <jrrech@hotmail.com> schreef in bericht news:eCrQ2%23osDHA.3196@TK2MSFTNGP11.phx.gbl... > ActiveSheet.ResetAllPageBreaks > > -- > Jim Rech > Excel MVP > > ...

Correct Way To Wait
I have seen this talked about but still not sure which is the correct way to do this. Either way below seems to work. A form is opened for the user to click on something. The form is modless. It cannot be modal. I want other events in the app (timer driven) and outside the app to have max process time while the user is thinking. so, do I use Sleep or a system timer or ...? Do DoEvents Sleep 200& Loop While bLoop or Do DoEvents WaitMS 200& Loop While bLoop The user clicking a button changes the state of bLoop to False. WaitMS is a Crea...

M07
In Money 2007 Deluxe, I've created a report and saved it in My Favorties. Is there a way to delete some of the other reports I don't want any longer without deleting all of them? Mark In microsoft.public.money, Mark Fields wrote: >In Money 2007 Deluxe, I've created a report and saved it in My Favorties. >Is there a way to delete some of the other reports I don't want any longer >without deleting all of them? > Go to Reports->FavoriteReports->OrganizeFavorites. Select the report, and click Delete at the bottom. Wow, I cannot believe I have not seen...

Best way to read an xml file
Hi; If I need to read an XML file - basically the SAX approach where I just need each node in order - one pass, read-only - what is the best way to do this. It looks like it's XmlReader but I want to verify that. ??? -- thanks - dave "David Thielen" <thielen@nospam.nospam> wrote in message news:BEA51BCB-B200-4104-B061-CA32FECD9DFD@microsoft.com... > If I need to read an XML file - basically the SAX approach where I just need > each node in order - one pass, read-only - what is the best way to do this. Yes, if your only requirement is a firehose forward reader,...

Basic--How do I make dates look a certain way in a cell?
Here's what I'd like to do: I'd like to type 41507 in a cell, and have it display as "4/15/07" or "04/17/07". Instead, it pops up some crazy date like 7/31/85. I've figured out why this is (the number indicates which day since January 1, 1900, and inserts that date). But I can't figure out if it is possible to do what I want. Is there a technique for typing in a date without slash marks or periods, and have these appear in the cell automatically? Thanks for any help you can give. ddc This will *look* like the date you want to display, but it ce...

Splitting a database
Hi, I have broken my database into several stages. I have implemented the first stage and this is simply the database (with basic features) on a central computer and a shortcut added to each user's computer. I know this is quite risky but at this stage only one person is cupturing and editing the data and the rest is viewing information and printing reports. I am still building on new features of the database and this would include adding more fields to some tables. 1 - Could i now split my database and give each user a FE, given the fact that i will still be adding and removin...

Any way to enforce security with Outlook Sync?
I have found that I can synchronize data to an Outlook user that the user does not have rights to when online. This is a HUGE security hole, and I was hoping that there was a patch or some way to force the Outlook synchronization rules to be filtered properly by the CRM security model. In our configuration all accounts are seen by all people, and I think that is where this breaks. The default "My contacts" rule syncs all contacts with a parent that I have downloaded or that I own. Unfortunately we have different BU's and we do not want people to be able to synchronize an...

"United Way" Style Campaign Thermomoter Fundraising Graph
I am trying to do an narrow bar graph for a fundraising campaign, % of goal. My version of Excel is 2003. Hi, There are a bunch of examples here. http://www.andypope.info/charts/thermometer.htm Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "% of goal" <% of goal@discussions.microsoft.com> wrote in message news:E7304278-21ED-4EFF-A0F8-A3B82C8772EA@microsoft.com... >I am trying to do an narrow bar graph for a fundraising campaign, % of >goal. > My version of Excel is 2003. ...

Why does the right side of my paper not print (within margin) Pub
I've had this problem for awhile now, but the current document is a postcard I'm printing 4 to a page with a border around each one. The whole thing prints out just fine except for the right side of the page, which happens to be the whole side of the border. It is well within the margins. I've checked all the settings within Publisher 2003 and my printer program (Dell Photo AIO) that I can find. Thanks! ~Renee'~ Renee'''' wrote: > I've had this problem for awhile now, but the current document is a postcard > I'm printing 4 to a page with a...