请问我有两个线程或者说多个线程去访问一个静态方法,线程如下:
Thread threadOne = new Thread(new ThreadStart(StartThreadOne));
Thread threadTwo = new Thread(new ThreadStart(StartThreadTwo));
threadOne.Start();
threadTwo.Start();private static void StartThreadTwo()
{
Bitmap mapOne = GetBitmapByPicUrl("Url_One");
}
private static void StartThreadOne()
{
Bitmap mapTwo = GetBitmapByPicUrl("Url_Two");
}
然后静态方法如下:
/// <summary>
/// 获取网页图片
/// </summary>
/// <param name="m_PicUrl"></param>
/// <returns></returns>
public static Bitmap GetBitmapByPicUrl(string m_PicUrl)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_PicUrl);
req.Method = "GET";
req.Referer = m_PicUrl;
req.Connection = "true";
req.ContentLength = 0;
using (WebResponse web = req.GetResponse())
{
var resStream = web.GetResponseStream();
Bitmap sourcebm = new Bitmap(resStream);//初始化Bitmap图片
return sourcebm;
}
}
请问这个多线程去访问会不会有问题,会不会出现死锁的情况,请大神详细解释一下,包括内存之间的关系。
上图是我自己整理的C#内存分配,担心你看不明白,我又在网上帮你找到个资料:
http://social.msdn.microsoft.com/Forums/sharepoint/zh-CN/cf143c51-7e6f-4e4e-bdd0-6f148170bec5/c
你看看
恩,咋了?
ThreadStatic
加个锁。