如何在线程上调用具有以下 header 的方法?
public void ReadObjectAsync<T>(string filename)
{
// Can't use T in a delegate, moved it to a parameter.
ThreadStart ts = delegate() { ReadObjectAcync(filename, typeof(T)); };
Thread th = new Thread(ts);
th.IsBackground = true;
th.Start();
}
private void ReadObjectAcync(string filename, Type t)
{
// HOW?
}
public T ReadObject<T>(string filename)
{
// Deserializes a file to a type.
}
为什么你不能这样做...
public void ReadObjectAsync<T>(string filename)
{
ThreadStart ts = delegate() { ReadObject<T>(filename); };
Thread th = new Thread(ts);
th.IsBackground = true;
th.Start();
}
private void ReadObject<T>(string filename)
{
// Deserializes a file to a type.
}
我是一名优秀的程序员,十分优秀!