我想在Visual Studio中使用任务列表,但它确实缺少任务列表应该提供的几乎任何有用的功能.所以我在外部使用Todo-List来跟踪我需要完成的事情.将它们放在一个地方会很高兴.
那么有谁知道Visual Studio中任务列表的一个很酷的替换附加组件?
提前致谢!
我有一个在应用程序域中运行的控制台应用程序.应用程序域由自定义Windows服务启动.该应用程序使用父任务来启动多个有效的子任务.当计时器查找新工作时,可以有许多子任务在任何给定时间运行子项.
所有父任务的句柄位于任务列表中:
static List<Task> _Tasks = new List<Task>();
Run Code Online (Sandbox Code Playgroud)
当管理员更改xml配置文件时(或当呼叫服务关闭时),Windows服务可以通过在应用程序域槽中放置字符串令牌来向正在运行的应用程序发送停止信号.应用程序在计时器上运行并检查要在插槽中关闭的信号,然后尝试通过等待所有任务结束来优雅地结束它正在执行的操作.
任务开始如下:
Task parent = Task.Factory.StartNew(() =>
{
foreach (var invoiceList in exportBucket)
{
KeyValuePair<string, List<InvoiceInfo>> invoices = new KeyValuePair<string, List<InvoiceInfo>>();
invoices = invoiceList;
string taskName = invoices.Key; //file name of input file
Task<bool> task = Task.Factory.StartNew<bool>(state => ExportDriver(invoices),
taskName, TaskCreationOptions.AttachedToParent);
}
});
_Tasks.Add(parent);
Run Code Online (Sandbox Code Playgroud)
自定义GAC dll包含一个完成工作的类.GAC功能中没有共享对象.GAC类在每个子任务中实例化:
Export export = new Export();
Run Code Online (Sandbox Code Playgroud)
每个子任务在执行期间的某个时刻调用方法:
foreach (var searchResultList in SearchResults)
{
foreach (var item in searchResultList)
{
if (item.Documents.Count > 0)
{
//TODO: this is …Run Code Online (Sandbox Code Playgroud) 如果活动A与任务T1相关且活动B与任务T2相关,我如何从活动B完成活动A?
我需要这个,因为我的应用程序可以从它的快捷方式或通过通知启动.
Node *head = &node1;
while (head)
{
#pragma omp task
cout<<head->value<<endl;
head = head->next;
}
#pragma omp parallel
{
#pragma omp single
{
Node *head = &node1;
while (head)
{
#pragma omp task
cout<<head->value<<endl;
head = head->next;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在第一个块中,我只创建了没有并行指令的任务,而在第二个块中,我使用了并行指令和单指令,这是我在论文中看到的常见方法.我想知道它们之间的区别是什么?顺便说一句,我知道这些指令的基本含义.
我的评论中的代码:
void traverse(node *root)
{
if (root->left)
{
#pragma omp task
traverse(root->left);
}
if (root->right)
{
#pragma omp task
traverse(root->right);
}
process(root);
}
Run Code Online (Sandbox Code Playgroud) 如果这是异步的,它将返回没有错误,为什么它在没有异步的情况下抛出错误,async在这个操作中毫无价值.
public Task<int> countUp()
{
string compare = txtTag.Text;
int count = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (compare == dataGridView1[0, i].Value.ToString())
{
BeginInvoke(new Action(() =>
{
count++;
txtCount.Text = count.ToString();
}));
}
}
return count;
}
Run Code Online (Sandbox Code Playgroud) 如您所知,您可以使用标签在GFM (github flavoured markdown)中创建任务列表
- [ ] for unchecked task
- [x] for a checked task
Run Code Online (Sandbox Code Playgroud)
我想知道是否有可能通过在提交中记录它来检查给定问题的任务列表中的任务.
Task在C#中实例化了一个或多个对象,例如:
var tasks = new List<Task>
{
Task.Factory.StartNew(MyWorker.DoWork),
Task.Factory.StartNew(AnotherWorker.DoOtherWork)
};
Run Code Online (Sandbox Code Playgroud)
有没有办法Action从任务对象中获取方法?换句话说,我可以返回Action的MyWorker.DoWork从它的任务是什么?
我正在尝试记录每个任务的状态,如下所示:
Task.WaitAll(tasks.ToArray(), new TimeSpan(0, 0, 1));
var msg = tasks.Aggregate(string.Empty,
(current, task) =>
current + $"{task.Action}: {task.Status}{Environment.NewLine}");
Run Code Online (Sandbox Code Playgroud)
字符串值msg将是:
MyWorker.DoWork RanToCompletion
AnotherWorker.DoOtherWork Running
Run Code Online (Sandbox Code Playgroud)
({task.Action}我的样本部分不存在,当然也不会编译)
我试图连续执行2个任务,但第二个任务在第一个任务完成之前运行,因为它是等待的
var task1 = new Task(async () =>
{
Trace.WriteLine("before delay");
await Task.Delay(1000);
Trace.WriteLine("after delay");
});
task1.ContinueWith(task => Trace.WriteLine("continued"));
task1.Start();
task1.Wait();
Run Code Online (Sandbox Code Playgroud)
我想引出输出
before delay
after delay
continued
Run Code Online (Sandbox Code Playgroud)
但我明白了
before delay
continued
Run Code Online (Sandbox Code Playgroud)
有没有办法阻止task1而不占用线程?
我有一个使用C#和.NET Framework 4.0运行任务开发的Windows窗体应用程序.
我很抱歉问这个问题,但我不知道发生异常的地方.这是堆栈跟踪:
One or more errors occurred.
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at MyCompany.Dispositivos.Plugins.TICAnKorr.DeviceTICAnKorr.StopLive()
at MyCompany.Dispositivos.Plugins.TICAnKorr.VisorTICAnKorrMini.StopRemote()
at MyCompany.Dispositivos.InterfazDispositivos.ICBaseVisor.DesasociarDispositivo()
at MyCompany.Dispositivos.InterfazDispositivos.ControlMosaico.DesasociarTodosLosPaneles()
at MyCompany.Dispositivos.InterfazDispositivos.ControlMosaico.CrearControlSeleccionado(DeviceBase device)
at MyCompany.Dispositivos.InterfazDispositivos.ControlMosaico.icPanelViewer_MouseDown(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.UserControl.OnMouseDown(MouseEventArgs e)
at MyCompany.Dispositivos.InterfazDispositivos.VisorDeMosaico.mousedown(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.UserControl.OnMouseDown(MouseEventArgs e)
at MyCompany.BasicInterface.Controles_Basicos.ICLabel.lblText_MouseDown(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, …Run Code Online (Sandbox Code Playgroud) 以下是我在项目中用于安排任务的代码片段
mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
//Do Something
}
}, interval, interval);
Run Code Online (Sandbox Code Playgroud)
这很好用.我提到间隔后得到事件.但如果将日期设置为小于设置中的当前值,则无法发送任何事件.
有谁知道为什么会发生这种行为?