gpt4 book ai didi

c# - 让用户指定定时器时间?

转载 作者:可可西里 更新时间:2023-11-01 11:34:01 25 4
gpt4 key购买 nike

我希望 DispatcherTimer 从文本框中读取时间值:objTextBox。我尝试了这段代码,但似乎 TimeSpan 与字符串不兼容,还是我做错了什么?

错误:参数 1:无法从“string”转换为“long”

还有;文本框中的时间是否必须如下所示:0、0、1 或 00:00:01?

代码在这里:

    private void testing()
{
string theText = objTextBox.Text;
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(listjob3_Tick);
dispatcherTimer.Interval = new TimeSpan(theText);
dispatcherTimer.Start();
}

最佳答案

要将字符串转换为 TimeSpan,请使用 TimeSpan.Parse(str)

关于c# - 让用户指定定时器时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16022054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com