| | |
help in threading problem
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 83
Reputation:
Solved Threads: 2
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
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.
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
C# Syntax (Toggle Plain Text)
[STAThread] private static void newInstance() { //the following code also exists in Main() method Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
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.
Why don't you call 
It probably has something to do with that visual studio hosting process. It always mucks my projects up so I shut it off.
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.
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; namespace daniweb { public partial class frmProcess : Form { public frmProcess() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Process.Start(Application.ExecutablePath); } } }
You're welcome
Please mark this thread as solved if you have found an answer to your question and good luck!
Please mark this thread as solved if you have found an answer to your question and good luck!
![]() |
Similar Threads
- threading problem (Python)
- Threading problem (Java)
- Threading Problem (VB.NET)
- problem on threading (C#)
- Multi threading problem. (C++)
Other Threads in the C# Forum
- Previous Thread: Array Issues
- Next Thread: C#Express & Access DB not flowing to Form
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagridview dataset datetime degrees development draganddrop drawing encryption enum excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






