停止和在.net中的任务完成后,除去线 [英] stopping and removing thread after completing of task in .net

查看:115
本文介绍了停止和在.net中的任务完成后,除去线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了在C#在这里我创建一个线程来执行一个调度事件一个窗口的应用程序。现在这个应用程序将运行整整一天,它会创建一个线程为每个事件每个执行。分配给该线程任务完成后,如何从内存中删除线程。我不希望使用线程池,分配给它的最大线程特定数量限制的线程创建的数量。

I have developed one window application in C# where i am creating one thread to perform one schedule event. now this application will run the whole day and it will create one thread for each execution of each event. How to remove threads from memory after task assigned to that thread is completed. I dont want to restrict number of threads creation by using thread pool and assigning it a specific count for max thread.

推荐答案

在一个线程完成它的执行将不再消耗内存,这将是垃圾收集器收集它的目标,所以不要担心。但是,如果您使用的是工作工作的IDisposable 对象,这是一个很好的做法,处置,当它完成它的执行了。

After a thread finishes its execution it will no longer consume memory and it will be target for the garbage collector to collect it, So don't worry about it. however if you are using Task, the Task is IDisposable object, it is a good practice to Dispose it when it finishes its execution.

这篇关于停止和在.net中的任务完成后,除去线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆