Slipstick Forums  

Go Back   Slipstick Forums > Outlook Programming > Programming Add-ins

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-06-2009, 07:50 AM
nitwalke@gmail.com nitwalke@gmail.com is offline
Junior Member
 
Join Date: Nov 2009
Posts: 4
Default Drag and drop attachment in outlook addin

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

Reply With Quote
  #2  
Old 11-06-2009, 02:41 PM
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: Drag and drop attachment in outlook addin

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
>


Reply With Quote
  #3  
Old 11-09-2009, 01:27 AM
nitwalke@gmail.com nitwalke@gmail.com is offline
Junior Member
 
Join Date: Nov 2009
Posts: 4
Default Re: Drag and drop attachment in outlook addin

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:
Originally Posted by Ken Slovak - [MVP - Outlook] View Post
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
>
Reply With Quote
  #4  
Old 11-10-2009, 10:01 AM
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: Drag and drop attachment in outlook addin

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?


Reply With Quote
  #5  
Old 11-19-2009, 04:52 AM
nitwalke@gmail.com nitwalke@gmail.com is offline
Junior Member
 
Join Date: Nov 2009
Posts: 4
Default Re: Drag and drop attachment in outlook addin

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:
Originally Posted by Ken Slovak - [MVP - Outlook] View Post
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?
Reply With Quote
Reply

Bookmarks


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -4. The time now is 04:27 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.