problem of "DragDrop registration did not succeed" error in VS2005beta2

J

Jacky Kwok

Dear All:

I am try to port my app to Dotnet2.0 using VS2005 beta2.
VisualStudio 2005 beta2 version 8.0.50215.44
Dotnet framework version 2.0.50215

I got a problem if I run a "Form" in a new Thread and the Form has a
ListBox and the "listBox.AllowDrop = true".

The error detail are
===========================
************* Exception Text **************
System.InvalidOperationException: DragDrop registration did not succeed.
---> System.Threading.ThreadStateException: Current thread must set to
single thread apartment (STA) mode before OLE calls can be made. Ensure
that your Main function has STAThreadAttribute marked on it.
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
--- End of inner exception stack trace ---
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.ListBox.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
===============================


My code can be simplified as following lines:

In Form1 (main form), an event will create Form2 and run the
"Form2.RunJobMonitor"

===Form1.cs===
private void button1_Click(object sender, EventArgs e)
{
new Form2().RunJobMonitor();
}
==============

In Form2, the form object will be run in another thread.
The Form2 just contain one ListBox only (in the testing program).
If the "listBox.AllowDrop = true", the error happens.

===Form2.cs====
public void RunJobMonitor()
{
//run itself in a new thread
Thread th = new Thread(new ThreadStart(MonThreadFun));
th.Start();
}
private void MonThreadFun()
{
Application.Run(this); //error in this line
}
===============

I cannot understand what is the problem. The code had been run in Dotnet
1.0 and 1.1 for long time.

I found some info in the link,
"http://www.datadynamics.com/ShowPost.aspx?PostID=75732" , 'When you run
a WinForms project with an End User Report Designer control on the form,
a "DragDrop registration did not succeed." exception occurs.'

However, I cannot understand what is "End User Report Designer control".


Finally, I found that if add the
"SetApartmentState(ApartmentState.STA);" in the new thread. The error
can be solved.

===Form2.cs=====
public void RunJobMonitor()
{
//run itself in a new thread
Thread th = new Thread(new ThreadStart(MonThreadFun));
th.SetApartmentState(ApartmentState.STA); //<- solve problem
th.Start();
}
================

Can anyone tell me what happen?



Moreover, I want to ask that anyone know what happen in news server
"privatenews.microsoft.com".
I found that it almost has no new post after April 2005.
Does microsoft stop to maintain it?

Then, where should be the formal position to discuss the beta
VisualStudio2005?


Thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top