473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

.net 2.0 Register DragDrop Failed - STAThreadAttribute

Hello,

When I am attempting to start a form (with DragDrop enabled) within a
new thread, I get the following exception. This is ONLY the case with
..NET 2.0 and did not occur in 1.1. I ABSOLUTELY MUST start this form in
a new thread. There is no getting around this. The fact that it
functioned properly when compiled for 1.1 is highly irritating.

{System.InvalidOperationException: DragDrop registration did not
succeed. ---> System.Threading.ThreadStateException: 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.
at System.Windows.Forms.Control.SetAcceptDrops(Boolea n accept)
--- End of inner exception stack trace ---
at System.Windows.Forms.Control.SetAcceptDrops(Boolea n accept)
at System.Windows.Forms.Control.set_AllowDrop(Boolean value)
at Kapsules.frmWidget.InitializeComponent()
at Kapsules.frmWidget..ctor()
at Kapsules.CWidgetThread.Load()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()}

I would appreciate any help with this matter, as my posts on the
Microsoft newgroups and websites have gone unanswered. Could be another
one of those lovely 'features' that snuck its way in there.

Thanks

Dec 12 '05 #1
5 8782
I ABSOLUTELY MUST start this form in a new thread.


Then you must also set the thread's ApartmentState property to STA.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 13 '05 #2
Have you not even bothered to read that post? Good lord.

Setting a thread to STA might as well be not starting a new thread at
all. STA threads do not behave any where close to standard MTA threads.
Imagine if you will 30 forms all perfoming some intense operation at
once, continually. Hence the requirement and use of an MTA thread. And
to nip it in the bud before it's even mentioned - No, this cannot be
solved by the BackgroundWorker.

The million dollar questions is how to circumvent Microsoft's
'brilliant' slew of new insanely strict thread safety implementations
to make this function PROPERLY as it did in .NET 1.1.

Dec 13 '05 #3
Have you not even bothered to read that post? Good lord.
More than once. If you have that attitude towards people trying to
help you, I kind of understand why your previous posts have gone
unanswered.

STA threads do not behave any where close to standard MTA threads.
Why exactly is it that your code can't run in an STA? What kind of
work do these threads do that require them all to show UI?

The million dollar questions is how to circumvent Microsoft's
'brilliant' slew of new insanely strict thread safety implementations
to make this function PROPERLY as it did in .NET 1.1.


Certain features - drag and drop being one of them - have always
required running in an STA. It's just that they enforce it now. Even
if you code seemed to work in 1.1 it was still broken.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 13 '05 #4
'Even if you code seemed to work in 1.1 it was still broken.'

That's got to be one of the most rediculous things I've ever seen. 'my
car appears to be moving forward when I depress the gas pedal, but in
reality, it's not. mystical forces are afoot!'

I've since Implemented the interfaces myself and have fallen back on
using the OLE DragDrop API set to get this working again. Despite the
MVP's opinion, drag drop most definately works (and safely I might add)
using this method.One might have thought that the people behind .NET
would have fallen back on WM_DROPFILES as an alternative method for
forms started within an MTA thread, but apparently that was just beyond
their capabilities.

At any rate, If anyone should come across this thread and be in the
same situation, please email me and I'll be happy to provide the code
required.

Dec 13 '05 #5
I don't really want to get into an argument but I must verify that code that
"worked" in dot.net prior to V2 would sometimes not work if you try to use
the UI in a thread other than the thread that created the UI.

My app would on occation have a problem that no one could capture. When it
was converted to use V2 , low and behold there was the error indication and
after taking this to task and fixing it we encountered no further problems.

If you want to bash MS then bash them for letting V1/1.1 allow the
compilation of code that they knew would not always work correctly.

Lloyd Sheen

<po*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
'Even if you code seemed to work in 1.1 it was still broken.'

That's got to be one of the most rediculous things I've ever seen. 'my
car appears to be moving forward when I depress the gas pedal, but in
reality, it's not. mystical forces are afoot!'

I've since Implemented the interfaces myself and have fallen back on
using the OLE DragDrop API set to get this working again. Despite the
MVP's opinion, drag drop most definately works (and safely I might add)
using this method.One might have thought that the people behind .NET
would have fallen back on WM_DROPFILES as an alternative method for
forms started within an MTA thread, but apparently that was just beyond
their capabilities.

At any rate, If anyone should come across this thread and be in the
same situation, please email me and I'll be happy to provide the code
required.

Dec 15 '05 #6

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

Similar topics

7
by: Kate | last post by:
Hi: I have a form with a picture box and some command buttons to make certain shapes appear in the picture box. The shapes are drawn on blank UserControls added like this: 'at top of form...
0
by: | last post by:
does anybody know what to do with a message like this: 'System.InvalidOperationException' = occurred in system.windows.forms.dll Additional information: DragDrop registration failed. This...
1
by: KS | last post by:
In want to visualy drag a Button to a Label and when I depress the mousebutton on top of the label I want to show some dato from the Button in a MsgBox - that's my primary goal. I have made a...
0
by: Flack | last post by:
Hello, Is it possible to find out how many methods are listening to a certain event? For example, if a number of methods subscribed to a controls DragDrop event using +=, can I find out how many...
0
by: Christopher Weaver | last post by:
"DragDrop registration failed" is the error message I'm getting on frmTasksInstance.ShowDialog() in the snippet below: frmTasks frmTasksInstance = new frmTasks(); frmTasksInstance.ShowDialog();...
2
by: Roy Gunnarsson | last post by:
Hello all, I have a VERY simple windows application that decrypts data files we receive from a partner. The decryption is handled by a COM component our partner provided us with (thus we have no...
0
by: Gene Hubert | last post by:
Well, it seems fundamental to me anyway. Hopefully it is simple enough. The question is for when the source for the dragdrop is a different application that the target for the dragdrop. How...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.