I've an application where we use Tasks. We also modified the cultureInfo(we use the EN-US language, but keep the date/number format), and we use .Net 4.0.
The application has a lot of thread and task, and we have a factory for the creation of Task/Threads.
For the thread, we have the following code, to ensure that every thread is launched with the correct CurrentCulture:
//This is basically only the constructor, but it describe well how we create the Thread:
public MonitoredThread(ThreadStart threadStart, string name, bool isBackground = false)
{
m_threadStart = threadStart;
m_name = name;
m_isBackground = isBackground;
Thread = new Thread(ThreadWorker)
{
Name = name,
IsBackground = isBackground,
CurrentCulture = CustomCultureInfo.CurrentCulture,
CurrentUICulture = CustomCultureInfo.CurrentCulture
};
}
But for the Tasks, I don't know how to implement this kind of mechanism:
public static Task ExecuteTask(Action action, string name)
{
MonitoredTask task = new MonitoredTask(action, name);
return Task.Factory.StartNew(task.TaskWorker);
}
Any idea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…