System.InvalidOperationException: The calling thread must be STA

Nov 28, 2008 at 10:19 AM
Hi,

I played a little with MEF and I ran in two problems in first place ...

1. When i Plug dll in folder while my App is running i got an Exception (file is hold by another proces ... something like this... )...
    - So i made one simple change in  AttributedAssemblyPartCatalog(string codeBase) method. I Added Thread.Sleep(500); as first line and things worked fine...

2. I instantiate my MefService (and MEFContainer) on Main UI Thread and this works fine if plugable module is in folder when app starts .. But if I add it latter while app is runnning
    i got updated mu ExportCollection on wrong Thread. I of course can manage this by checking and switching to the correct thread , but  i believe you will manage this in MEF as you do have sychcontext? Am i right by assuming this...

and just to say, I really like the simplicity of MEF, I already integrated it in our product with this few changes ...

Thanks,
Dec 2, 2008 at 1:37 AM
Edited Dec 2, 2008 at 1:37 AM
   At which point do you create the DirectoryCatalog? We do use the SyncronizationContext, however even in UI apps it doesn't get creates until the main loop starts pumping, which is generally a result of calling Application.Run() or such - depending on the presentation technology you are using.
If you want the updates to have a strong UI thread affinity, you will need to create the DirectoryCatalog after the message loop is created (e.g not in program.Main, but it Application.OnStartup).
   Admitedly, this is not very transparent, but we are aware of this issue and might address this in the future.
   Thanks
    Oleg
Dec 2, 2008 at 9:46 AM
Hi Oleg,

Well could be ... I'll check
I use this in combination with Unity Container and Implemented this as Service so I'll check when exactly this is called and I'll let you ...

Thanks,



From: notifications@codeplex.com
To: salelas@hotmail.com
Date: Mon, 1 Dec 2008 17:37:15 -0800
Subject: Re: System.InvalidOperationException: The calling thread must be STA [MEF:41002]


.ExternalClass {font-family:Verdana;font-size:0.75em;} .ExternalClass #EC_ThreadNotificationFooter {border-top:1px solid #ccc;color:gray;} .ExternalClass #EC_ThreadNotificationPostBody {margin-bottom:2em;} .ExternalClass {font-family:Verdana;font-size:0.75em;} .ExternalClass #EC_ThreadNotificationFooter {color:gray;border-top:1px solid #ccc;} .ExternalClass #EC_ThreadNotificationPostBody {margin-bottom:2em;} From: olegl
At which point to you create the DirectoryCatalog? We do use the SyncronizationContext, however even in UI apps it doesn't get creates until the main loop starts pumping, which is generally a result of calling Application.Run() or such - depending on the presentation technology you are using.
If you want the updates to have a strong UI thread affinity, you will need to create the DirectoryCatalog after the message loop is created (e.g not in program.Main, but it Application.OnStartup).
Admitedly, this is not very transparent, but we are aware of this issue and might address this in the future.
Thanks
Oleg
Read the full discussion online.
To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)
To start a new discussion for this project, email MEF@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Discover the new Windows Vista Learn more!