我有几个按钮可以将文本字符串数据从文本框发送到另一页上的文本块。请参阅下面的代码。
private void button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Properties["obj1"] = textbox.Text;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
Application.Current.Properties["obj2"] = textbox2.Text;
}
如果我想使用按钮单击来停止/取消正在发送的信息,我将如何执行此操作?
接收文本字符串的页面如下
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
textBlock1.Text = Application.Current.Properties["obj1"]?.ToString();
textBlock2.Text = Application.Current.Properties["obj2"]?.ToString();
}
真的你不能停止发送,你只能撤消结果。在用户有时间做出反应之前,发送过程早已超出您的代码范围,这是反应时间的限制。就像你不能拔掉 cat5 来阻止电子邮件像老笑话一样发送一样,当你重新考虑发送时,它早已消失了,并且超出了你的控制范围。
毕竟取消/停止需要接近原始发送的时间,并增加半秒的人为反应时间......
您的最佳解决方案可能只是将该键的字典值设置为 null,但由于我们没有看到您的任何用法,因此这只是对什么对您有用的最佳猜测。