I have a console application running in the application domain. An application domain starts with a Windows user service. The application uses parent tasks to run several child tasks that work. There can be many parental tasks with children working at any given time when the timer is looking for a new job.
the handle of all parent tasks is in the task list:
static List<Task> _Tasks = new List<Task>();
The Windows service can send a stop signal to the running application by placing a string token in the application domain slot when the administrator modifies the xml configuration file (or when the calling service disconnects). The application runs on a timer and checks that the signal closes in the slot, and then tries to gracefully complete what it does, waiting for the completion of all tasks.
Tasks are launched as follows:
Task parent = Task.Factory.StartNew(() =>
{
foreach (var invoiceList in exportBucket)
{
KeyValuePair<string, List<InvoiceInfo>> invoices = new KeyValuePair<string, List<InvoiceInfo>>();
invoices = invoiceList;
string taskName = invoices.Key;
Task<bool> task = Task.Factory.StartNew<bool>(state => ExportDriver(invoices),
taskName, TaskCreationOptions.AttachedToParent);
}
});
_Tasks.Add(parent);
The GAC user library contains a class that does this work. There are no shared objects in the GAC function. A GAC class is created in each child task:
Export export = new Export();
Each child task invokes a method at some point during execution:
foreach (var searchResultList in SearchResults)
{
foreach (var item in searchResultList)
{
if (item.Documents.Count > 0)
{
var exported = export.Execute(searchResultList);
totalDocuments += exported.ExportedDocuments.Count();
}
}
}
searchResultList . , export.Execute . , . , :
foreach (var task in _Tasks){task.Wait();}
while (_Tasks.Count(t => t.IsCompleted) != _Tasks.Count){}
, :
Error in Export.Execute() method: System.Threading.ThreadAbortException: Thead was being aborted at WFT.CommonExport.Export.Execute(ICollection '1 searchResults)
, , , .
, GAC , .
UPDATE
. , ...
, :
while (_Tasks.Count(t => t.IsCompleted) != _Tasks.Count){}
,
Task.WaitAll()
, . , , , , , :
AppDomain.CurrentDomain.SetData("Status", "Not Exporting");
. , , , , SetData "Not Exporting". , , , , ThreadAbortException. SetData .