我正在使用 SAP .NET 连接器 3.0 并尝试使用单独的线程登录,这样我就可以让 UI 显示一种登录动画。
我正在使用 Async 和 Await 开始登录,但 UI 在登录期间挂起大约 10 秒。
这是代码,它很粗糙,因为我正在快速起草一个程序。
async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Busy.Visibility = System.Windows.Visibility.Visible; // Shows progress animation
if (await SAPLogin()) // Waits for login to finish, will always be true at the moment
{
await GetData(); // does things with sap
Busy.Visibility = System.Windows.Visibility.Collapsed; // Hides progress animation
}
}
private Task<bool> SAPLogin()
{
bool LoggedIn = true;
return Task.Run(() =>
{
Backend = new BackendConfig();
RfcDestinationManager.RegisterDestinationConfiguration(Backend);
SapRfcDestination = RfcDestinationManager.GetDestination(MyServer); // MyServer is just a string containing sever name
SapRap = SapRfcDestination.Repository;
BapiMD04 = SapRap.CreateFunction("MD_STOCK_REQUIREMENTS_LIST_API");
BapiMD04.SetValue("WERKS", "140");
return LoggedIn;
});
}
我只能想象任务中的某些东西正在使用 UI?
编辑1:抱歉忘了解释是什么GetData()
。
GetData()
在 SAP 中运行各种报告(大量代码)。从视觉上看,我知道它什么时候在那里,因为我的小登录动画将从“登录”变为“抓取数据”。当我看到 UI 挂起时,我看到它是在“登录”阶段。登录动画有一个简单的圆圈旋转。这会在登录中途停止,然后在大约 5 秒后继续。
编辑 2: 悬挂似乎发生在这条线上
SapRfcDestination = RfcDestinationManager.GetDestination(MyServer);
编辑 3:在我看到 UI 挂起的地方暂停应用程序时添加了线程的照片。