修复头像显示偶尔出现的异常BUG,v1.4.3

This commit is contained in:
dathlin
2017-09-20 21:55:43 +08:00
parent 51ed4031c5
commit e12ebd7416
5 changed files with 156 additions and 85 deletions

View File

@@ -70,43 +70,48 @@ namespace ClientsLibrary
public UserPortrait UserPortrait { get; }
private void LoadPortraitByFileName(string fileName)
{
if(IsHandleCreated)
{
if(InvokeRequired)
{
BeginInvoke(new Action(() =>
{
LoadPortraitByFileName(fileName);
}));
return;
}
try
{
pictureBox_UserPortrait.LoadAsync(fileName);
}
catch(Exception ex)
{
UserClient.LogNet?.WriteException("加载图片异常!", ex);
}
}
}
private void pictureBox_UserPortrait_Click(object sender, EventArgs e)
{
UserPortrait.ChangePortrait();
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolLoadLargePortrait), null);
UserPortrait.ChangePortrait(LoadLargeProtrait,UnloadLargeProtrait);
}
private void ThreadPoolLoadLargePortrait(object obj)
{
UserPortrait.LoadUserLargePortraint(LoadPortraitByFileName);
Thread.Sleep(200);
UserPortrait.LoadUserLargePortraint(LoadLargeProtrait, UnloadLargeProtrait);
}
private void UnloadLargeProtrait()
{
if (IsHandleCreated && InvokeRequired)
{
BeginInvoke(new Action(() =>
{
UnloadLargeProtrait();
}));
return;
}
pictureBox_UserPortrait.Image = null;
}
private void LoadLargeProtrait(string fileName)
{
if (IsHandleCreated && InvokeRequired)
{
BeginInvoke(new Action(() =>
{
LoadLargeProtrait(fileName);
}));
return;
}
pictureBox_UserPortrait.ImageLocation = fileName;
}
#endregion
#region
@@ -240,6 +245,9 @@ namespace ClientsLibrary
#endregion
#region
private void treeView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
@@ -298,6 +306,7 @@ namespace ClientsLibrary
}
}
#endregion
}
}