在计时器中获取流 [英] get stream in timer
本文介绍了在计时器中获取流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
为什么不能但是
hello
why can''t but
Client.GetStream();
在计时器中吗?
并给出错误
Cannot access a disposed object. Object name: ''System.Net.Sockets.TcpClient''.
??
请我帮忙
这是代码
in timer ?
and give an error
Cannot access a disposed object. Object name: ''System.Net.Sockets.TcpClient''.
??
please I need a help
this is the code
public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
{
Bitmap result = new Bitmap(nWidth, nHeight);
using (Graphics g = Graphics.FromImage((Image)result)) g.DrawImage(b, 0, 0, nWidth, nHeight);
return result;
}
NetworkStream myns;
byte[] arrImage;
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
Bitmap bt;
bt = new Bitmap(CaptureScreen.CaptureDesktopWithCursor());
pictureBox1.Image = ResizeBitmap(bt, 877, 482);
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
arrImage = ms.GetBuffer();
ms.Close();
listBox1.SetSelected(0, true);
ClientInfo clientInfo = (ClientInfo)listBox1.SelectedItem;
Client = clientInfo.Client;
Thread t = new Thread(new ParameterizedThreadStart(send));
t.Start();
timer1.Enabled = true;
}
private void send(object client)
{
try
{
myns = Client.GetStream();
BinaryWriter mysw = new BinaryWriter(myns);
mysw.Write(arrImage);//send the stream to above address
mysw.Close();
myns.Close();
myns.Flush();
Client.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
第
行中的错误
the error in line
myns = Client.GetStream();
该项目在服务器上进行截图并发送图片.作为客户端(远程PC)
the project is there server take a screenshot and send the pic. to client as(remote pc)
推荐答案
添加此空间:导入System.Net.Sockets
add this space :Imports System.Net.Sockets
这篇关于在计时器中获取流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文