线程间操作ui
2021-05-07 10:30
标签:send label detail ext1 invoke string OLE textbox post 线程间操作ui 标签:send label detail ext1 invoke string OLE textbox post 原文地址:https://www.cnblogs.com/liuyudong0825/p/13184313.htmlusing EasyNetQ.Logging;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
private static IScheduler _scheduler;
SynchronizationContext synchronizationContext = null;
delegate void ChangeText1(string strmessage);
private AsyncOperation operation;
public event EventHandler labclick;
public Form1()
{
InitializeComponent();
synchronizationContext = SynchronizationContext.Current;
operation = AsyncOperationManager.CreateOperation(null);
}
//public int localPort = 0;
private void Form1_Load(object sender, EventArgs e)
{
IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
IPAddress[] ip = ipe.AddressList;
IPAddress iPAddress = ip[1];
//IPAddress localIp = IPAddress.Parse("127.0.0.1");
IPEndPoint iep = new IPEndPoint(ip[1], 80);
this.label2.Text = iep.Port.ToString();
string strip= ip.Select(o=>o).Where(o=>o.AddressFamily.ToString()== "InterNetwork").FirstOrDefault().ToString();
this.label1.Text = strip;
//ChangeText1 = (strmessage) => { setText1value(strmessage); };
SettextBox2Value(Thread.CurrentThread.ManagedThreadId.ToString(),"");
//
//PlaySound();
Thread thread = new Thread(new ThreadStart(GetMessage));
thread.IsBackground = true;
thread.Start();
//ConsoleLogProvider logProvider = new ConsoleLogProvider();
//logProvider.SetLogCallBack((log) =>
//{
// this.rchMessage.AppendText(log);
//});
//MusicJob._printLogCallBack = (log) =>
//{
// synchronizationContext.Send((obj) =>
// {
// this.textBox2.AppendText(log.ToString());
// }, null);
//};
//MusicJob._printLogCallBack = delegate (string log,string strThread)
//{
// synchronizationContext.Post(delegate { SettextBox2Value(log.ToString(), strThread.ToString()); }, null);
//};
MusicJob._printLogCallBack = delegate (string log, string strThread)
{
synchronizationContext.Post(delegate { SettextBox2Value(log.ToString(), strThread.ToString()); }, null);
};
//LogProvider.SetCurrentLogProvider(logProvider);
}
public string SettextBox2Value(string log,string strThread)
{
this.textBox2.AppendText(log.ToString()+ strThread+ Thread.CurrentThread.ManagedThreadId.ToString());
return log.ToString() + strThread;
}
//public Form1(int localPort)
//{
// this.localPort = localPort;
//}
///