gpt4 book ai didi

c# - 运行 ClickOnce 部署版本的 WPF 应用程序时的奇怪行为

转载 作者:行者123 更新时间:2023-11-30 22:50:58 25 4
gpt4 key购买 nike

我们有一个基于导航的 WPF 应用程序。直接从 Visual Studio 运行时它工作正常,或者即使我们将文件复制到另一个目录或另一台计算机并在那里运行它。

我们使用 ClickOnce 和大多数工具在 Internet 上部署应用程序这通常不会造成任何问题。

然而,时不时地,它会完全卡住,你会得到经典的“应用程序 xxxx 没有响应”和无响应的 UI。

这不会每次都发生,只有在使用部署版本时才会发生。(即使我们在开发机器上测试它)。

As I am typing this message, we are starting and quiting the deployed version many times in order to try and reproduce the behaviour... sometimes it will happen 10 times in a row, and then it'll work fine the next 20 times. With no indication as to what might be causing it. (Just managed to make it happen)

为了向您展示我的意思,这是一个屏幕截图:

[ alt text ][空]

双击列表框中的第一项时会发生这种情况:

   LLCOverviewPage llcOverview = new LLCOverviewPage((Controller)this.lstControllers.SelectedItem);
this.NavigationService.Navigate(llcOverview);

应用程序永远保持这种状态,不会抛出任何异常。

LLCOverViewPage 的构造函数如下所示:

public LLCOverviewPage(Controller CurrentController)
{
InitializeComponent();

this.currentController = CurrentController.ToLightLinkController();
this.updateControllerInfo();
}

updateControllerInfo()方法显示页面信息,然后调用一个方法获取之前加载的更多信息来自 SQL Compact 3.5 数据库:

    private void updateControllerInfo()
{
//Update the UI with general properties
this.lblDeviceName.Content = this.currentController.ShortName;
this.lblEthernetAddress.Content = this.currentController.Eth0.EthernetAddress.ToString();
this.lblTcpPort.Content = this.currentController.Eth0.TcpPort.ToString();
this.lblActuatorThroughputMode.Content = (this.currentController.Dali.ActuatorThroughputMode ? "Enabled" : "Disabled");
this.lblNetmask.Content = (this.currentController.Eth0.Netmask != null ? this.currentController.Eth0.Netmask.ToString() : String.Empty);
this.lblDefaultGateway.Content = (this.currentController.Eth0.DefaultGateway != null ? this.currentController.Eth0.DefaultGateway.ToString() : String.Empty);

//Update the UI with the ballasts
this.updateBallastList();
}

private void updateBallastList()
{
this.lstBallasts.ItemsSource = null;

List<BallastListViewItem> listviewItems = new List<BallastListViewItem>();
foreach (DaliBallast ballast in this.currentController.Dali.Ballasts.OrderBy(b => b.ShortAddress))
{
listviewItems.Add(new BallastListViewItem(ballast,this.currentController.SerialNumber));
}

this.lstBallasts.ItemsSource = listviewItems;
}

就是这样。构建页面时不会发生任何其他事情。

毫无异常(exception),因为应用程序没有崩溃,为了找到问题所在,我几乎没有什么可继续的。

SQL Compact 数据库存储在用户应用程序文件夹中,所以部署版本使用与普通版本相同的数据库,那里没有区别。

所以,需要说明的是,这个问题只发生在部署版本中!(在装有 Windows XP 和 Windows Vista 的不同机器上测试过)

关于可能导致此类事情发生的任何想法,或者我可能会尝试什么来追查这个问题?

更新

Using some good old debugging (writing log information to a file) I was able to determine all of my code succesfully excecutes and the application only freezes after that.

因此,如果您再看一下正在创建的页面的构造函数:

    public LLCOverviewPage(Controller CurrentController)
{
InitializeComponent();

this.currentController = CurrentController.ToLightLinkController();
this.updateControllerInfo();
}

在 this.updateControllerInfo() 之后是应用程序卡住的地方时。这会超出我的代码范围吗?也许是 WPF 错误?

更新 2我检查了 Windows 中的应用程序事件日志,它是这样说的:

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Application Hang" />
<EventID Qualifiers="0">1002</EventID>
<Level>2</Level>
<Task>101</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2008-11-04T15:55:55.000Z" />
<EventRecordID>1630</EventRecordID>
<Channel>Application</Channel>
<Computer>DEVTOP</Computer>
<Security />
</System>
<EventData>
<Data>LLCControl.exe</Data>
<Data>1.0.0.0</Data>
<Data>2f4</Data>
<Data>01c93e95c29f9da5</Data>
<Data>20</Data>
<Binary>55006E006B006E006F0077006E0000000000</Binary>
</EventData>
</Event>

二进制文本说:未知,猜猜我完全被坑了......

更新 3如果我将列表框的事件处理程序代码更改为:

LLCOverviewPage llcOverview = new LLCOverviewPage((Controller)this.lstControllers.SelectedItem);
MessageBox.Show("Navigating Now");
this.NavigationService.Navigate(llcOverview)

它告诉我应用程序仅在导航时卡住!

更新 4我将一些事件处理程序连接到 NavigationService。当事件被触发时,处理程序只需写入日志。结果如下所示:

17:51:35 Navigating 17:51:35 Navigated 17:51:35 LoadCompleted

那么为什么这会被遗忘呢?

最佳答案

我已经能够将问题追溯到代码当数据绑定(bind)发生时调用,这保证了在这里发现一个新问题:

SQL 2 LINQ query (called by databinding) completely freezing WPF application

关于c# - 运行 ClickOnce 部署版本的 WPF 应用程序时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/262017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com