修复登录 UI线程bug
This commit is contained in:
1 parent
f772c35ede
commit
be54dff06b
1 file changed
+19
-11
@@ -165,8 +165,11 @@ namespace _29WxOrderWpf.ViewModels
|
||||
}
|
||||
});
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
||||
AutoLogin();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -180,11 +183,12 @@ namespace _29WxOrderWpf.ViewModels
|
||||
/// <summary>
|
||||
/// 自动登录店铺后台
|
||||
/// </summary>
|
||||
private void AutoLogin()
|
||||
private async void AutoLogin()
|
||||
{
|
||||
if (OpenType != EnumOpenType.login && buyer == null)
|
||||
return;
|
||||
|
||||
_ = Application.Current.Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
if (CefWebBrowser == null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(InitUrl))
|
||||
@@ -220,11 +224,11 @@ namespace _29WxOrderWpf.ViewModels
|
||||
{
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
||||
// cef138必须init后方可设置或删除cookie
|
||||
|
||||
while (!CefWebBrowser.IsBrowserInitialized || !CefWebBrowser.GetBrowser().MainFrame.IsValid)
|
||||
Thread.Sleep(20);
|
||||
await Task.Delay(20);
|
||||
WPFCEFBrowser.DeleteCookie(CefWebBrowser.GetCookieManager(null));
|
||||
|
||||
//cef 138 如果没有设置RequestContext 可能为空,直接getCookieManager
|
||||
@@ -259,22 +263,26 @@ namespace _29WxOrderWpf.ViewModels
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
if (CefWebBrowser.IsLoading)
|
||||
Thread.Sleep(100);
|
||||
await Task.Delay(100);
|
||||
//Thread.Sleep(100);
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(1500, 2000));
|
||||
|
||||
await Task.Delay(Randomx.GetId(1500, 2000));
|
||||
if (!_isWindowLoaded)
|
||||
return;
|
||||
|
||||
while (!CefWebBrowser.Address.StartsWith(shopLoginUrl))
|
||||
while (!CefWebBrowser.Address?.StartsWith(shopLoginUrl) ?? false)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
await Task.Delay(1000);
|
||||
if (!_isWindowLoaded)
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user