
首先把流程源码放出来 这些代码也包含了一个定时器和记录前台显示,每天几点执行一次,需要拿去,从最底层开始
<Button
x:Name="btnStart"
Width="100"
Height="30"
Margin="5"
HorizontalAlignment="Left"
Click="btnStart_Click"
Content="启老余动" />
<TextBox
Name="txtLog"
Grid.Row="1"
Grid.ColumnSpan="2"
AcceptsReturn="True"
Foreground="Black"
HorizontalScrollBarVisibility="Auto"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" />
然后到数据层
public async Task Execute(string[] args)
{
try
{
await Task.Run(() =>信神
{
LoadDisplay("你迟到了")
})
}
catch (Exception e)
{
//LoadDisplay($"请求接口时出现异常{e.Message}")
}
}
/// <summary>
/// 输出日志信息
/// </summary>
/// <param name="news"></param>
public void LoadDisplay(string news)
{
this.txtLog.Dispatcher.BeginInvoke((Action)delegate
{
this.txtLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss " + news + "\r\n"))
if (IsVerticalScrollBarAtBottom)
{
this.txtLog.ScrollToEnd()
}
})
}
调用层
复制代码
/// <summary>
/// //要执行的任务
/// </summary>
//滑含亏/ <param name="state"></param>
private async void DoTask(object state)
{
string[] args = new string[0]
//执行功能...
await Execute(lines)
//再次设定
SetTaskAtFixedTime()
}
复制代码
开始new一个计时器
复制代码
/// <summary>
/// //设定定时执行
/// </summary>
public void SetTaskAtFixedTime()
{
DateTime now = DateTime.Now
DateTime oneOClock = DateTime.Today.AddHours(7.0)//晨7:00
if (now >oneOClock)
{
oneOClock = oneOClock.AddDays(1.0)
}
int msUntilFour = (int)(oneOClock - now).TotalMilliseconds
var t = new System.Threading.Timer(DoTask)
t.Change(msUntilFour, Timeout.Infinite)
}
复制代码
最后 按钮点击事件
多线程 *** 作只要不是在UI线程中 *** 作一般不会致UI挂死,你可以这样做,很简单:把要上传的文件名放入一个List里面,然后再new thread时罩唤候把list传出,上传时在文件list中去一个文件name,记住对list *** 晌棚作要加lock.
好了,这样就可以解决你的问题物谨凯了
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)