help in threading problem

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 74
Reputation: MxDev has a little shameless behaviour in the past 
Solved Threads: 2
MxDev MxDev is offline Offline
Junior Poster in Training

help in threading problem

 
0
  #1
Sep 26th, 2009
hi guys,
I'm writting a simple text editor using visual studio 2008. When I'm trying to

make a new instance of the application using the following code which is existed

in Main() method

  1. [STAThread]
  2. private static void newInstance() {
  3.  
  4. //the following code also exists in Main() method
  5.  
  6. Application.EnableVisualStyles();
  7. Application.SetCompatibleTextRenderingDefault(false);
  8. Application.Run(new Form1());
  9. }

the application creates a new instance, but the problem is when try to open,

save, and any other action the application generate a "ThreadStateException"

which says

"Current thread must be set to single thread apartment (STA) mode before

OLE calls can be made. Ensure that your Main function has

STAThreadAttribute marked on it. This exception is only raised if a debugger is

attached to the process."

How to solve this bug, or where I can find an answer???

Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,285
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 586
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: help in threading problem

 
0
  #2
Sep 26th, 2009
Why don't you call Process.Start() and create a new instance? I don't know why you would _want_ to implement what you are describing but it is a neat idea

It probably has something to do with that visual studio hosting process. It always mucks my projects up so I shut it off.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10.  
  11. namespace daniweb
  12. {
  13. public partial class frmProcess : Form
  14. {
  15. public frmProcess()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. Process.Start(Application.ExecutablePath);
  23. }
  24. }
  25. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 74
Reputation: MxDev has a little shameless behaviour in the past 
Solved Threads: 2
MxDev MxDev is offline Offline
Junior Poster in Training

Re: help in threading problem

 
0
  #3
Sep 27th, 2009
Thanks sknake, I appreciate your help, it worked fine!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,285
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 586
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: help in threading problem

 
0
  #4
Sep 27th, 2009
You're welcome

Please mark this thread as solved if you have found an answer to your question and good luck!
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 937
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 152
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: help in threading problem

 
0
  #5
Sep 27th, 2009
Just an FYI and you still need to mark this question as SOLVED.

FYI: Not sure why a text editor application would launch a new instance of itself. Have you considered using an MDI Form?
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC