因为它正在被另一个进程使用? [英] because it is being used by another process ?
问题描述
大家好,
我正在使用gsmcomm库制作通过3g调制解调器发送短信的应用程序.
通过单击连接"按钮连接到端口后,将执行下面的代码.然后,当我关闭表单并尝试再次连接到同一端口时,它会显示.被另一个进程使用."它在任务管理器后面工作.如果我说删除任务",也没有问题
但是,如果我通过单击断开连接按钮来关闭表单..我重新打开表单并重新连接后就没有问题..
我该怎么办?
对于关闭事件,我写了port.Disconnect();
但没有执行..
int port = int .Parse(drpPort.Text);
int baud = int .Parse(drpBaudRate.Text);
int 超时= int .Parse(drpTimeOut.Text);
comm = 新 GsmCommMain(端口,波特率,超时);
comm.Open();
如果(comm.IsOpen())
{
btnBaglan.Enabled = false ;
btniptal.Enabled = true ;
MessageBox.Show(" , Dikkat!",MessageBoxButtons.OK,MessageBoxIcon.Information);
lblBeklemede.Text = " ;
bilgiler();
}
其他
{
comm.Open();
}
由于您打开了端口却没有关闭端口,因此该端口一直处于打开状态并一直在使用中,直到垃圾收集器将其释放出来为止.内存并处理它.我建议,如果可能的话,请使用using
块构造端口实例,或确保完成后调用Close and Dispose.
值得养成对所有实现IDisposable的对象执行此操作的习惯-在某些时候,如果您不这样做,它就会像在这里一样咬住您.
>
Hi guys,
Im making an application sending sms via 3g modem using the gsmcomm library.
After i connect to the port via clicking Connect button , the code below is executed.Then when I close the form and when i try to connect again to the same port..It says "The process cant access the file..because it is being used by another process " ..and it works behind Task manager..if i say "drop the task"..there is no prob as well
But if i close the form by clicking disconnect button..there is no problem after i reopen form and reconnect..
What can i do it ?
For closing event , i wrote port.Disconnect();
but doesnt execute..
int port = int.Parse(drpPort.Text);
int baud=int.Parse(drpBaudRate.Text);
int timeout = int.Parse(drpTimeOut.Text);
comm = new GsmCommMain(port, baud,timeout);
comm.Open();
if (comm.IsOpen())
{
btnBaglan.Enabled = false;
btniptal.Enabled = true;
MessageBox.Show("Porta başarılı bir şekilde bağlandınız!!", "Dikkat!", MessageBoxButtons.OK, MessageBoxIcon.Information);
lblBeklemede.Text = "Porta Bağlandı";
bilgiler();
}
else
{
comm.Open();
}
Because you open the port and do not close it, the port remains open and in use until teh Garbage Collector comes along to free up the memory and Disposes of it. I would suggest that if possible you use ausing
block to construct your port instance, or ensure that you call Close and Dispose on it when you have finished with it.
It is worth getting into the habit of doing this for all objects that implement IDisposable - at some point if you don''t, it will come back to bite you, as it does here.
这篇关于因为它正在被另一个进程使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!