C# 两个线程之间取值问题

.Net技术 码拜 10年前 (2014-12-07) 1550次浏览 0个评论

截屏信息类型
class Screenshots
{
public static List<ScreenshotsThread> Classlist = new List<ScreenshotsThread>();
public static void Init()
{
ArrayList list = new ArrayList();
list.Add(“192.168.9.202:8000:31202”);
list.Add(“192.168.9.213:8000:31213”);
foreach (string strvalue in list)
{
ScreenshotsThread screenshotsthread = null;
string[] str = strvalue.Split(‘:’);
screenshotsthread = new ScreenshotsThread();
screenshotsthread.setAddr(str[0].ToString());
screenshotsthread.setPort(str[1].ToString());
screenshotsthread.setId(str[2].ToString());
screenshotsthread.start();
Classlist.Add(screenshotsthread);
}
}
}

//截屏处理线程
class ScreenshotsThread
{

private String IpAddress = “”;
private string IPport = “”;
private String tid = “”;
Thread thread = null;
static object _getTerminalObj = new object();//锁定对象
byte[] buffer = new byte[1024];
Socket socket;
bool _state = true;
string _info;

//IP地址
public void setAddr(String IpAddr)
{
IpAddress = IpAddr;
}

public bool state
{
get { return _state; }
set { _state = value; }
}

public string Info
{
get { return _info; }
set { _info = value; }
}

//端口号
public void setPort(string Port)
{
IPport = Port;
}
//机器编码
public void setId(String id)
{
tid = id;
}

public void start()
{
if (thread == null)
thread = new Thread(run);
thread.IsBackground = true;
thread.Start();
}

public void run()
{
try
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IpAddress, int.Parse(IPport));
socket.Receive(buffer);
}
catch (Exception ex)
{
throw new Exception(“读取截屏据数据存在错误!”);
}
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}

void ReceiveMessage(IAsyncResult ar)
{
try
{
var socket = ar.AsyncState as Socket;
var length = socket.EndReceive(ar);
byte[] reallData = new byte[length];
Array.Copy(buffer, reallData, length);
string str = System.Text.Encoding.UTF8.GetString(reallData);
if (str.IndexOf(“确认要退出系统吗”) > -1)
{
Info = tid + “:确认要退出系统吗”;
}
else if (str.Contains(“请输入”) && str.Contains(“选择竞猜内容”))
{
Info = tid + “:请输入选择竞猜内容”;
}
else if (str.Contains(“请输入”) && str.Contains(“内数字选择日期”))
{
Info = tid + “:请输入内数字选择日期”;
}
else if (str.Contains(“请输入”) && str.Contains(“数字选择日期”))
{
Info = tid + “:请输入数字选择日期”;
}
else if (str.Contains(“没有第”) && str.Contains(“场比赛”))
{
Info = tid + “:没有第场比赛”;
}
else if (str.Contains(“周”) && str.Contains(“没有赛事”))
{
Info = tid + “:周没有赛事”;
}
else if (str.Contains(“倍数最小为”) && str.Contains(“请重新输入”))
{
Info = tid + “:倍数最小为请重新输入”;
}
else if (str.Contains(“当前操作尚未完成”) && str.Contains(“是否确定要退出”))
{
Info = tid + “:当前操作尚未完成是否确定要退出”;
}
else if (str.Contains(“请输入”) && str.Contains(“按钮上的数字进行选择”))
{
Info = tid + “:请输入按钮上的数字进行选择”;
}
else if (str.IndexOf(“倍投范围为”) > -1)
{
Info = tid + “:倍投范围为”;
}
FuncWrite(“输出:”+Info);
Thread.Sleep(10);
}
catch (Exception ex)
{
// FuncWrite(ex.Message);
}
finally
{
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}
}

void FuncWrite(object text)
{

try
{
String dir = Environment.CurrentDirectory + “\\..\\log\\”;
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
String FileName = dir + DateTime.Now.ToString(“yyyy-MM-dd”) + “.log”;
String Msg = DateTime.Now.ToString(“HH:mm:ss.fff”) + ”   ” + text + “\r\n”;
File.AppendAllText(FileName, Msg);
System.Console.Write(Msg);
}
catch (Exception ex)
{
}

}
}
—-
//另一个线程方法调用截屏信息线程类取值会出现卡死情况

//兑奖方法
public  bool prizeTicketData(Ticket ticket)
{
int z = 0;
string tid=””;
bool state = true;
bool jieguo = false;
//从实例化类对象集合取消息内容

while (state)
{
foreach (ScreenshotsThread str in Screenshots.Screenshotslist)
{
if (str.Info != “” && str.Info != null)
{
string[] strno = strInfo.Split(‘:’);
//判断弹出消息内容 与机器编号是否一样
if (strno[1].Contains(“兑奖成功”) &&tid == strno[0])
{
base.sendCtlChar(“ENTER”);//发送指令表示兑奖成功
state = false;
jieguo = true;
break;
}
else
{
//清空截屏信息
str.Info=””;
state = true;
jieguo = false;
}
}
}
//没获取截屏信息继循环5秒后。没有获取正确信息返回flase
if (z == 50)
{
state = false;
jieguo = false;
break;
}
z++;
list.Clear();
Thread.Sleep(100);
}

}

—- 100分

阻塞在这里了吧 var length = socket.EndReceive(ar);
看下非阻塞啊
看下System.Threading.ManualResetEvent,线程等待WaitOne()和set()
应该是等待socket接收完你才能取值吧
socket编程,来人看下我说的对不对

—-
socket  这种方式接收值 会不会有问题。

—-
有没有大牛出来指点一下。这个问题卡啦我好久啦!!!
—-
一直找不到问题出在什么地方。

—-
代码太多,注释太少
建议把跟通信无关的,只不过是判断需要显示什么字符串的东西都拿掉
然后挑重点,写个伪代码,把关键的会产生阻塞的代码写清楚就好了
—-

class Screenshots
{
//类列表
public static List<ScreenshotsThread> Classlist = new List<ScreenshotsThread>();
public static void Init()
{
//机器连接列表
ArrayList list = new ArrayList();
list.Add(“192.168.9.202:8000:31202”);
list.Add(“192.168.9.213:8000:31213”);
//多机器生成启线程类实列并类实例加载到类列表
foreach (string strvalue in list)
{
ScreenshotsThread screenshotsthread = null;
string[] str = strvalue.Split(‘:’);
screenshotsthread = new ScreenshotsThread();
screenshotsthread.setAddr(str[0].ToString()); //IP地址
screenshotsthread.setPort(str[1].ToString());//端口
screenshotsthread.setId(str[2].ToString()); //机器编码
screenshotsthread.start(); //启动线程
Classlist.Add(screenshotsthread);  //线程类实例加载到类列表
}
}
}
//截屏处理线程
class ScreenshotsThread
{
private String IpAddress = “”;
private string IPport = “”;
private String tid = “”;
Thread thread = null;
byte[] buffer = new byte[1024];
Socket socket;
string _info;
//IP地址
public void setAddr(String IpAddr)
{
IpAddress = IpAddr;
}
//截屏信息
public string Info
{
get { return _info; }
set { _info = value; }
}
//端口号
public void setPort(string Port)
{
IPport = Port;
}
//机器编码
public void setId(String id)
{
tid = id;
}
//启动线程
public void start()
{
if (thread == null)
thread = new Thread(run);
thread.IsBackground = true;
thread.Start();
}

//启动线程
public void run()
{
try
{
//创建套接字发送数据到一个TCP连接。
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//尝试连接
socket.Connect(IpAddress, int.Parse(IPport));

//接收数据
socket.Receive(buffer);
}
catch (Exception ex)
{
throw new Exception(“读取截屏据数据存在错误!”);
}
//socket异步的方法接收数据
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}

//socket异步的方法接收数据
void ReceiveMessage(IAsyncResult ar)
{
try
{
var socket = ar.AsyncState as Socket;
var length = socket.EndReceive(ar);
byte[] reallData = new byte[length];
Array.Copy(buffer, reallData, length);
string str = System.Text.Encoding.UTF8.GetString(reallData);
if (str.IndexOf(“确认要退出系统吗”) > -1)
{
Info = tid + “:确认要退出系统吗”;
}
Thread.Sleep(10);
}
catch (Exception ex)
{
//获取异常信息并写入到日志文件
FuncWrite(ex.Message);
}
finally
{
//重新执行异步的方法接收数据
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}
}
}
—-
class Screenshots
{
//类列表
public static List<ScreenshotsThread> Classlist = new List<ScreenshotsThread>();
public static void Init()
{
//机器连接列表
ArrayList list = new ArrayList();
list.Add(“192.168.9.202:8000:31202”);
list.Add(“192.168.9.213:8000:31213”);
//多机器生成启线程类实列并类实例加载到类列表
foreach (string strvalue in list)
{
ScreenshotsThread screenshotsthread = null;
string[] str = strvalue.Split(‘:’);
screenshotsthread = new ScreenshotsThread();
screenshotsthread.setAddr(str[0].ToString()); //IP地址
screenshotsthread.setPort(str[1].ToString());//端口
screenshotsthread.setId(str[2].ToString()); //机器编码
screenshotsthread.start(); //启动线程
Classlist.Add(screenshotsthread);  //线程类实例加载到类列表
}
}
}
//截屏处理线程
class ScreenshotsThread
{
private String IpAddress = “”;
private string IPport = “”;
private String tid = “”;
Thread thread = null;
byte[] buffer = new byte[1024];
Socket socket;
string _info;
//IP地址
public void setAddr(String IpAddr)
{
IpAddress = IpAddr;
}
//截屏信息
public string Info
{
get { return _info; }
set { _info = value; }
}
//端口号
public void setPort(string Port)
{
IPport = Port;
}
//机器编码
public void setId(String id)
{
tid = id;
}
//启动线程
public void start()
{
if (thread == null)
thread = new Thread(run);
thread.IsBackground = true;
thread.Start();
}

//启动线程
public void run()
{
try
{
//创建套接字发送数据到一个TCP连接。
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//尝试连接
socket.Connect(IpAddress, int.Parse(IPport));

//接收数据
socket.Receive(buffer);
}
catch (Exception ex)
{
throw new Exception(“读取截屏据数据存在错误!”);
}
//socket异步的方法接收数据
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}

//socket异步的方法接收数据
void ReceiveMessage(IAsyncResult ar)
{
try
{
var socket = ar.AsyncState as Socket;
var length = socket.EndReceive(ar);
byte[] reallData = new byte[length];
Array.Copy(buffer, reallData, length);
string str = System.Text.Encoding.UTF8.GetString(reallData);
if (str.IndexOf(“确认要退出系统吗”) > -1)
{
Info = tid + “:确认要退出系统吗”;
}
Thread.Sleep(10);
}
catch (Exception ex)
{
//获取异常信息并写入到日志文件
FuncWrite(ex.Message);
}
finally
{
//重新执行异步的方法接收数据
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}
}
}
—-
Z65443344  麻烦帮忙看看,谢谢!!
—-
public  bool prizeTicketData(Ticket ticket)
这个方法是在哪里调用的,怎么看也不是以线程方式启动的
—-
这个socket 是可以区取截屏信息。
我在另一个多线程获取这个截屏信息 Info值

while (state)
{
foreach (ScreenshotsThread str in Screenshots.Screenshotslist)
{
if (str.Info != “” && str.Info != null)
{
string[] strno = strInfo.Split(‘:’);
//判断弹出消息内容 与机器编号是否一样
if (strno[1].Contains(“兑奖成功”) &&tid == strno[0])
{
base.sendCtlChar(“ENTER”);//发送指令表示兑奖成功
state = false;
jieguo = true;
break;
}
else
{
//清空截屏信息
str.Info=””;
state = true;
jieguo = false;
}
}
}
//没获取截屏信息继循环5秒后。没有获取正确信息返回flase
if (z == 50)
{
state = false;
jieguo = false;
break;
}
z++;
list.Clear();
Thread.Sleep(100);
}
—-
重复的话就不要反复说了
我就是想问你这个东西在哪里定义的,如何调用的
你自己说是在另一个线程里,但是我看你的函数定义,它根本就不是线程函数啊
—-

//兑奖类
class PrizeQueue
{
public static ArrayList QueueThread = new ArrayList();
private PrizeQueueThread pqt = null;
public static void Init()
{
XmlDocument xml = new XmlDocument();
xml.Load(“SystemConfig.xml”);

//读取队列配置
XmlNodeList nodelist = xml.SelectSingleNode(“config”).SelectSingleNode(“TicketQueue”).ChildNodes;
foreach (XmlNode xn in nodelist)
{
Hashtable ht = new Hashtable();
XmlNodeList xnlist = xn.ChildNodes;
foreach (XmlNode xn1 in xnlist)
{
ht.Add(xn1.Attributes[“name”].Value.ToString(), xn1.Attributes[“value”].Value.ToString());
}
//启动兑奖线程
PrizeQueueThread pqt = new PrizeQueueThread();
pqt.setConfig(ht);
pqt.start();
QueueThread.Add(pqt);
}
}
}

//兑奖线程
class PrizeQueueThread : BaseThread
{
private Hashtable ht = null;
Thread thread = null;
static object _getTerminalObj = new object();//锁定对象

//取得出票队列名称
public String getQueueName()
{
try
{
if (ht != null)
return ht[“GameID”].ToString();
return “”;
}
catch (Exception ex)
{
return “”;
}
}

//设置出票队列配置
public void setConfig(Hashtable htConfig)
{
ht = htConfig;
}

//取得出票队列配置
public String getConfig(String name)
{
if (ht.ContainsKey(name))
{
return ht[name].ToString();
}
return “”;
}
//启动线程
public void start()
{
if (thread == null)
thread = new Thread(run);
thread.IsBackground = true;
thread.Start();
}

public void run()
{
//数据库初始化
DatabaseMgr dbm = new DatabaseMgr();
OracleConnection conn = dbm.getConn();

String sql = “”;
//建立TICKET队列(ARRAYLIST)
ArrayList alPrizeQueue = new ArrayList();

while (true)
{
OracleTransaction ot = null;
try
{

if (alPrizeQueue.Count == 0)
{
//查询未打票 // order by INSERT_TIME
String GameID = ht[“GameID”].ToString();
sql = “select t1.id, t1.ticket_id, t1.ticket_password , t2.game_id,t2.PRINT_READTIME, t2.GAME_ISSUE, t2.PRINT_DONETIME from print_win t1, print_ticket t2 where t1.id = t2.id and (t1.prize_flag = 0 or t1.prize_flag = -1) and t2.game_id = ‘” + GameID + “‘”;
DataTable dt = dbm.ExecuteQuery(sql, conn);

//查出的结果记录为0的情况
if (dt.Rows.Count == 0)
{
Thread.Sleep(1000);
continue;
}
//更新打印状态为打印中
foreach (DataRow dr in dt.Rows)
{
String id = dr[“ID”].ToString();
sql = “update PRINT_WIN set PRIZE_FLAG = -1 where ID ='” + id + “‘”;
dbm.ExecuteNonQuery(sql, conn);
}

//将查询记录放入兑奖队列中
foreach (DataRow dr in dt.Rows)
{
Ticket ticket = new Ticket();
ticket.ID = dr[“ID”].ToString();
ticket.GAME_ID = dr[“GAME_ID”].ToString();
ticket.GAME_ISSUE = dr[“GAME_ISSUE”].ToString();
ticket.TICKET_ID = dr[“TICKET_ID”].ToString();
ticket.TICKET_PASSWORD = dr[“ticket_password”].ToString();
ticket.PRINT_READTIME = dr[“PRINT_READTIME”].ToString();
ticket.PRINT_DONETIME = dr[“PRINT_DONETIME”].ToString();
alPrizeQueue.Add(ticket);
}
}

//将查询出的记录放入队列中进行打印

Ticket ticket=null;
while (alPrizeQueue.Count != 0)
{

//取得打印线程对象
while (true)
{
//执行兑奖操作
tt = prizeTicketData(ticket);
//等于true 兑奖成功 执行相关操作
if (tt)
{
Thread.Sleep(100);
break;
}
else
{
//操作兑奖失败
}
}
//奖数据从对列中移除
lock (_getTerminalObj)
{
alPrizeQueue.RemoveAt(0);
}
}
}
catch (Exception ex)
{
//异常日志
LogMgr.WriteLog(ex.StackTrace + “:” + ex.Message);
if (ot != null)
ot.Rollback();
}
}
}

//兑奖方法
public  bool prizeTicketData(Ticket ticket)
{
int z = 0;
string tid=””;
bool state = true;
bool jieguo = false;
//从实例化类对象集合取消息内容

while (state)
{
foreach (ScreenshotsThread str in Screenshots.Screenshotslist)
{
if (str.Info != “” && str.Info != null)
{
string[] strno = strInfo.Split(‘:’);
//判断弹出消息内容 与机器编号是否一样
if (strno[1].Contains(“兑奖成功”) &&tid == strno[0])
{
base.sendCtlChar(“ENTER”);//发送指令表示兑奖成功
state = false;
jieguo = true;
break;
}
else
{
//清空截屏信息
str.Info=””;
state = true;
jieguo = false;
}
}
}
//没获取截屏信息继循环5秒后。没有获取正确信息返回flase
if (z == 50)
{
state = false;
jieguo = false;
break;
}
z++;
list.Clear();
Thread.Sleep(100);
}
}

}
—-
Screenshots.Screenshotslist
这东西在哪里定义的,为什么我找不到

还有,你使用了太多while循环了,整整嵌套了4层,真是不怕陷入死循环啊
—-
Screenshots.Screenshotslist  这个是截屏信息类初始化列表

//截屏信息类
class Screenshots

public static List<ScreenshotsThread> Classlist = new List<ScreenshotsThread>();

—-
可是定义的时候名字明明是Classlist
你使用的时候为什么要使用Screenshots.Screenshotslist,不报未定义的错误?
—-
我现在两个有不同多线程。
//截屏多线程类
Screenshots
//兑奖多线程类
PrizeQueue

兑线程类。每次根据截屏信息 去进行相关操作。截屏线程要不继去从机器获取截并信息存到线程类中 Info 变量中
PrizeQueue 类通过   Screenshots.Screenshotslist  类实例列表  调类型实例话类对象去获取  ScreenshotsThread.Info 值。

—-
截屏信息是可以获取到。兑奖在多线程。会出面卡死的情况。如只开一条线程,是不会出这种问题。两条线程下就会出卡死情况。是不是线程操作的没有加锁的原因吗?
—-
那这个Screenshotslist到底是哪里来的,你代码里根本没有啊,我ctrl+F搜索根本找不到
—-
你那个Info根本是个字符串
不加锁顶多是字符串拼接了一半的时候另一个线程就给取出来了,造成数据不完整
跟卡死不卡死没关系

问题是你现在代码不全,连定义都找不到,更不知道其他关键地方你是否省略了什么不得了的代码
—-
反而是一些无关紧要的代码放的太多,导致关键代码都找不到到底在哪里
—-
我把完整贴出来东西太多。

—-
如果你连代码里哪些是跟线程相关的内容,哪些是无关的内容都搞不清楚,就只能自己慢慢排查了
—-
你开另一个线程去获取信息,这个信息最终保存到哪里去了?
写入文件了,记录到数据库了,还是显示在界面上了?

base.sendCtlChar(“ENTER”);//发送指令表示兑奖成功
这是啥?

所以我一开始就让你写伪代码,而不是让你放出全部的代码
如果你放出了全部代码,但是都没有详细的注释,那跟没放一样
—-
我贴完整代码吧!
—-

namespace AutoPrintTicketSystem.src
{
class Screenshots
{
public static List<ScreenshotsThread> Screenshotslist = new List<ScreenshotsThread>();

#region 初始化terminal.xml配制信息
/// <summary>
/// 初始化terminal.xml配制信息
/// </summary>
/// <returns></returns>
public static bool Init()
{
try
{
//读取终端设备配置脚本
XmlDocument xml = new XmlDocument();
xml.Load(Application.StartupPath + @”\terminal.xml”);
XmlNodeList nodelist = xml.SelectNodes(“config”).Item(0).ChildNodes;

foreach (XmlNode xn in nodelist)
{
//如果配置中终端不可用,不会出现在终端列表中
String Enabled = xn.Attributes[“enabled”].Value.ToString();
if (Enabled == “false”) continue;
Hashtable ht = new Hashtable();

XmlNodeList xnlist = xn.ChildNodes;
foreach (XmlNode xn1 in xnlist)
{
String name = xn1.Attributes[“name”].Value.ToString();
if (name == “IPAddrScreenshots”)
{
ScreenshotsThread StatThread = null;
String value = xn1.Attributes[“value”].Value.ToString();
StatThread = new ScreenshotsThread();
StatThread.setId(xn.Attributes[“id”].Value.ToString());
StatThread.setAddr(value.Split(‘:’)[0]);
StatThread.setPort(value.Split(‘:’)[1]);
StatThread.start();
Screenshotslist.Add(StatThread);
}
}
}
return true;
}
catch (Exception ex)
{
LogMgr.WriteLog(ex.Message + “:” + ex.StackTrace);
return false;
}
}
#endregion

}

//票队列处理线程
class ScreenshotsThread : BaseThread
{
private String IpAddress = “”;
private string IPport = “”;
private String tid = “”;
byte[] buffer = new byte[1024];
Socket socket;
static object _getTerminalObj = new object();//锁定对象
// 输出信息
string _info = “”;

public string Info
{
get { return _info; }
set { _info = value; }
}

//IP地址
public void setAddr(String IpAddr)
{
IpAddress = IpAddr;
}
//端口号
public void setPort(string Port)
{
IPport = Port;
}
//机器编码
public void setId(String id)
{
tid = id;
}

public override void run()
{
try
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IpAddress, int.Parse(IPport));
socket.Receive(buffer);
}
catch (Exception ex)
{
throw new Exception(“读取截屏据数据存在错误!”);
}
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket);
}

private void ReceiveMessage(IAsyncResult ar)
{
try
{
var socket = ar.AsyncState as Socket;
var length = socket.EndReceive(ar);
byte[] reallData = new byte[length];
Array.Copy(buffer, reallData, length);
string str = System.Text.Encoding.UTF8.GetString(reallData);
//首面
if (str.IndexOf(“确认要退出系统吗”) > -1)
{
Info = tid + “:确认要退出系统吗”;
}
else if (str.Contains(“请输入”) && str.Contains(“内数字选择日期”))
{
// Info = tid + “:请输入内数字选择日期”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“请输入”) && str.Contains(“选择竞猜内容”))
{
// Info = tid + “:请输入选择竞猜内容”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“请输入”) && str.Contains(“数字选择日期”))
{
//Info = tid + “:请输入数字选择日期”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“没有第”) && str.Contains(“场比赛”))
{
//Info = tid + “:没有第场比赛”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“周”) && str.Contains(“没有赛事”))
{
//Info = tid + “:周没有赛事”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“倍数最小为”) && str.Contains(“请重新输入”))
{
//Info = tid + “:倍数最小为请重新输入”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“不在存场次为周”) && str.Contains(“比赛”))
{
// Info = tid + “:不在存场次为周比赛”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}

else if (str.Contains(“当前操作尚未完成”) && str.Contains(“是否确定要退出”))
{
//Info = tid + “:当前操作尚未完成是否确定要退出”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
}
else if (str.IndexOf(“倍投范围为”) > -1)
{
// Info = tid + “:倍投范围为”;
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
//按退格
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(14));
//按退格
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(14));
//按退格
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(14));
//按退格
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(14));
//输入1
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(2));
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));

}
else if (str.Contains(“请输入”) && str.Contains(“按钮上的数字进行选择”))
{
//Info = tid + “:请输入按钮上的数字进行选择”;
//按回车Enter
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(28));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
//按ESC
DeviceControl.sendData(tid, DeviceType.Keyboard, BitConverter.GetBytes(1));
}
else if (str.Contains(“兑奖成功”))
{
Info = tid + “:兑奖成功”;

}
else if (str.Contains(“不能兑奖”))
{
Info = tid + “:不能兑奖”;

}
else if (str.Contains(“不是中奖票号”))
{
Info = tid + “:不是中奖票号”;
}
else if (str.Contains(“序列号位数不够”))
{
Info = tid + “:序列号位数不够”;
}

else if (str.Contains(“密码位数不够”))
{
Info = tid + “:密码位数不够”;
}

Thread.Sleep(5);
}
catch (Exception ex)
{
throw new Exception(“读取截屏据数据存在错误!”);
}
finally
{
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMessage),socket);
}
}

}

}
—-
上面上截屏线程类
—-
总的问题就是。一个截屏线程在不断的获取信息类。别一个多线程。要不继获取值截屏线程内的信息进行下一个操作!
—-
结贴。问题已解决!!!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C# 两个线程之间取值问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!