C# 如何解决关闭/处置未处理的异常?
我正在开发一个Windows窗体应用程序,它是呼叫中心和CRM之间的一个连接器,我遇到了一个未处理的异常,我无法理解或解决 我的应用程序有:C# 如何解决关闭/处置未处理的异常?,c#,.net,winforms,C#,.net,Winforms,我正在开发一个Windows窗体应用程序,它是呼叫中心和CRM之间的一个连接器,我遇到了一个未处理的异常,我无法理解或解决 我的应用程序有: 带有一些控件和FlowControll窗格的MainForm,该窗格可能显示也可能不显示SearchForms的集合-确定 SearchForm-基本上是一个带有可单击单元格的DataGridView-根据列索引,单击将执行不同的操作-确定 DialForm-单击搜索表单上的单元格后加载,并允许i)取消(关闭表单确定);ii)拨打号码-问题-非常令人沮丧
- 带有一些控件和FlowControll窗格的MainForm,该窗格可能显示也可能不显示SearchForms的集合-确定
- SearchForm-基本上是一个带有可单击单元格的DataGridView-根据列索引,单击将执行不同的操作-确定
- DialForm-单击搜索表单上的单元格后加载,并允许i)取消(关闭表单确定);ii)拨打号码-问题-非常令人沮丧
///
/// DialForm Method - upon clicking «Dial Number» Button
///
private void dialButton_Click(object sender, EventArgs e)
{
//
// Piece of code to manage closing with DialFormCloseEventArgs
//
DialFormCloseEventArgs args = new DialFormCloseEventArgs();
args.toClose = this;
EventHandler<DialFormCloseEventArgs> eh = father.Search_CloseDialForm;
this.BeginInvoke(eh, new object[] { sender, args });
}
///
/// SearchForm Method - EventHandler to close DialForm and make call
///
public void Search_CloseDialForm(object sender, DialFormCloseEventArgs e)
{
string numberToDial = e.toClose.numberToDial.Text;
e.toClose.Dispose();
this.rePositionMainForm();
using (ConectorCTI.ConectorCTI ctiws = new ConectorCTI.ConectorCTI())
{
ctiws.Timeout = 180000;
// Synchronous Call
//ctiws.Dial(this.userLoginName, numberToDial, "");
// Assynchronous Call
ctiws.DialAsync(this.userLoginName, numberToDial, "");
}
}
///
///拨号方式-点击«拨号号码»按钮
///
私有无效拨号按钮\u单击(对象发送方,事件参数e)
{
//
//使用DialFormCloseEventArgs管理关闭的一段代码
//
DialFormCloseEventArgs args=新的DialFormCloseEventArgs();
args.toClose=这个;
EventHandler eh=father.Search\u CloseDialForm;
this.BeginInvoke(呃,新对象[]{sender,args});
}
///
///SearchForm方法-EventHandler关闭DialForm并拨打电话
///
公共无效搜索\u CloseDialForm(对象发送者,DialFormCloseEventArgs e)
{
字符串numberToDial=e.toClose.numberToDial.Text;
e、 toClose.Dispose();
这个.mainform();
使用(conectracti.conectracti-ctiws=new-conectracti.conectracti())
{
ctiws.Timeout=180000;
//同步呼叫
//ctiws.Dial(this.userLoginName,numberToDial,“”);
//同步呼叫
ctiws.dialsync(this.userLoginName,numberToDial,“”);
}
}
在处理对象之前,可能需要等待异步任务完成。差不多
using (ConectorCTI.ConectorCTI ctiws = new ConectorCTI.ConectorCTI())
{
var task = ctiws.DialAsync(this.userLoginName, numberToDial, "");
await task;
}
Seach_CloseDialForm事件处理程序返回到您处理的表单。然后可能发生的事情是不可预测的。至少在发布
e.toClose.Dispose()之前尝试调试代码>您显然正在处理您的表单。我是@CamiloTerevinto,你试过调试这个吗?为什么要创建变量任务?