【发布时间】:2012-01-31 20:44:56
【问题描述】:
这种情况可能看起来很奇怪,但这是我必须做的:
情况,我有一个共享点门户,并且存在这样一个问题,即在检索用户个人资料时可能会出现问题,当很多人在线并执行此类操作时可能会太慢,因此做了一个决定制作一个控制台应用程序来测试它。
控制台应用程序需要模拟用于检索用户配置文件的行为,就像许多不同的用户正在这样做一样。
而且一定要写日志。
第一个问题是这种测试是真正了解问题所在的好方法吗?
另一个问题是关于我的应用程序,我有一个奇怪的行为:
public class Program
{
static void Main(string[] args)
{
string filePath = @"C:\Users\User\Desktop\logfile.txt";
string siteUrl = @"http://siteurl";
int threads = 1;
//Multiplicator multiplicator = new Multiplicator(filePath, siteUrl, threads);
//Console.ReadLine();
for (int i = 0; i < 100; i++)
{
Thread t = new Thread(Execute);
t.Start();
}
Console.WriteLine("Main thread: " + Thread.CurrentThread.Name);
// Simultaneously, do something on the main thread.
}
static void Execute()
{
for (int i = 0; i < 100; i++)
{
using (SPSite ospSite = new SPSite(@"http://siteurl"))
{
SPServiceContext serviceContext = SPServiceContext.GetContext(ospSite);
UserProfileManager profileManager = new UserProfileManager(serviceContext);
UserProfile userProfile = profileManager.GetUserProfile("User Name");
string message = "Retrieved: " + userProfile.DisplayName + " on " +DateTime.Now + "by " Thread.CurrentThread.Name;
Console.WriteLine(message);
}
}
}
}
所以问题是我从来没有写过线程的名称,为什么? Thread.CurrentThread.Name 为空,是否正常,可能是我初始化线程错误?尽管许多消息来源都说是这样完成的?
【问题讨论】:
标签: c# multithreading