![]() |
|
#1
|
|||
|
|||
|
Hi All,
I have created outlook addin for outlook 2003 in vsto-2008. When I have tried to allow property 'allowDrag' to textbox it gives runtime exception "dragdrop registration did not succeed". I have searched on net, got suggestion to use threading. Thread t = new Thread(new ThreadStart(ShowForm)); t.SetApartmentState(ApartmentState.STA); t.Start(); public void ShowForm() { form.ShowDialog(); form.Dispose(); } Drag problem solved using thread but it give other problem in my application as follows a) When I right click on context menu then form disappear. b) Some time application hangs... Can I solve this problem without using thread? Because handling thread will almost change my design. Regards, Nit
|
|
#2
|
|||
|
|||
|
Are you trying to use the Outlook object model from a background thread?
That's not supported and will crash or hang Outlook. You have to marshal that background thread to the main process thread if you are using the object model. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "nitwalke@gmail.com" <nitwalkegmail.com.418a5m@invalid> wrote in message news:nitwalkegmail.com.418a5m@invalid... > > Hi All, > > I have created outlook addin for outlook 2003 in vsto-2008. When I have > tried to allow property 'allowDrag' to textbox it gives runtime > exception "dragdrop registration did not succeed". I have searched on > net, got suggestion to use threading. > > Thread t = new Thread(new ThreadStart(ShowForm)); > t.SetApartmentState(ApartmentState.STA); > t.Start(); > > public void ShowForm() > { > > form.ShowDialog(); > form.Dispose(); > } > > Drag problem solved using thread but it give other problem in my > application as follows > a) When I right click on context menu then form disappear. > b) Some time application hangs... > > Can I solve this problem without using thread? Because handling thread > will almost change my design. > > Regards, > Nit > > > -- > nitwalke@gmail.com > http://forums.slipstick.com > |
|
#3
|
|||
|
|||
|
Thanks Ken for replay.
I am not interested to use thread. I want to know, Can DragDrop registration will possible without using thread.I got following error while registering DragDrop event for text box. "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." I searched on net and got threading solution. But Can we solve this problem without using thread? Quote:
|
|
#4
|
|||
|
|||
|
I told you the only solution I know of.
-- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "nitwalke@gmail.com" <nitwalkegmail.com.41ez6x@invalid> wrote in message news:nitwalkegmail.com.41ez6x@invalid... > > Thanks Ken for replay. > I am not interested to use thread. I want to know, Can DragDrop > registration will possible without using thread.I got following error > while registering DragDrop event for text box. > "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." > > I searched on net and got threading solution. But Can we solve this > problem without using thread? |
|
#5
|
|||
|
|||
|
I will give details about my project.
In ThisAddIn class.. [STAThread] private void NewButtonClick() { Form frm = new Form(); frm.ShowDialog(); } and in form class. I have created textbox and set AllowDrop=True; it gives following error 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.OnHandleCreated(Event Args e) at System.Windows.Forms.Form.OnHandleCreated(EventArg s e) at System.Windows.Forms.Control.WmCreate(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m) at System.Windows.Forms.ContainerControl.WndProc(Mess age& m) at System.Windows.Forms.Form.WmCreate(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) I put [STAThread] above startup method [STAThread] private void ThisAddIn_Startup(object sender, System.EventArgs e) { . . } how should I proceed? Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Outlook addin formregion as a drop down | Sanaulah | Programming Add-ins | 6 | 10-23-2009 01:16 AM |
| RE: Email Drag and Drop Event in outlook | JIK | Programming VBA | 0 | 07-24-2009 07:25 AM |
| Drag & drop an email to a folder in outlook | Fred | Outlook General | 1 | 07-17-2009 11:08 AM |
| Implementing Drag and drop events in outlook | Ashish | Programming Add-ins | 7 | 07-06-2009 10:10 AM |
| Copy or Drag&Drop attachment from Outlook to [Program] Fails | steven filg | Outlook General | 5 | 03-12-2009 12:35 PM |