CLR Thread Problem

t0b1

Grünschnabel
Hallo,
ich muss gleich gestehn: Ich hab kein Plan, was CLR ist... :confused:
auf jeden Fall habe ich eine anwendung, die das Dateisystem durchsucht und dabei diverse sachen analysiert. Auf jeden fall ist das rel. rechenaufwändig und dauert.

Nach ca. 60 Sekunden kommt dann eine Fehlermeldung (!) :
Die CLR konnte 60 Sekunden lang keinen Übergang vom COM-Kontext 0x1a1520 zum COM-Kontext 0x1a1690 durchführen. Der Thread, der Besitzer des Zielkontexts/-apartments ist, wartet entweder, ohne Meldungen zu verschieben, oder verarbeitet eine äußerst lang dauernde Operation, ohne Windows-Meldungen zu verschieben. Eine solche Situation beeinträchtigt in der Regel die Leistung und kann sogar dazu führen, dass die Anwendung nicht mehr reagiert oder die Speicherauslastung immer weiter zunimmt. Zur Vermeidung dieses Problems sollten alle STA-Threads (Singlethread-Apartment) primitive Typen verwenden, die beim Warten Meldungen verschieben (z.B. CoWaitForMultipleHandles), und bei lange dauernden Operationen generell Meldungen verschieben.


Oke... da ich noch ein ziemlicher newbie bin, hab ich auch kein Plan was STA sein soll und wie man das benutzt....
könnt ihr mir bitte helfen?

Danke
t0b1 :)
 
STAs stellen virtuelle Prozesse dar, in denen alles der Reihe nach abgearbeitet wird.
MTAs hingegen arbeiten jeden Vorgang in einen eigenen Prozess ab. Das muss dementsprechend synchronisieren...

Aber google doch gleich am besten mal nach "sta mta msdn". Der erste Link ist ne PPT die Dich aufklärt.
Hier noch ein Auszug aus
http://blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx hat gesagt.:
Single Threaded Apartment (STA) – one affinitized thread is used to call all the objects residing in the apartment. Any call on these objects from other threads must perform cross-thread marshaling to this affinitized thread, which dispatches the call. Although a process can have an arbitrary number of STAs (with a corresponding number of threads), most client processes have a single Main STA and the GUI thread is the affinitized thread that owns it.

Multiple Threaded Apartment (MTA) – each process has at most one MTA at a time. If the current MTA is not being used, OLE may tear it down. A different MTA will be created as necessary later. Most people think of the MTA as not having thread affinity. But strictly speaking it has affinity to a group of threads. This group is the set of all the threads that are not affinitized to STAs. Some of the threads in this group are explicitly placed in the MTA by calling CoInitializeEx. Other threads in this group are implicitly in the MTA because the MTA exists and because these threads haven’t been explicitly placed into STAs. So, by the strict rules of OLE, it is not legal for STA threads to call on any objects in the MTA. Instead, such calls must be marshaled from the calling STA thread over to one of the threads in the MTA before the call can legally proceed.

Mit
C#:
[STAThread]
static void Main(){}
legst fest, dass dein Progamm in einem SingleThread-Apartment laufen soll.
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück