计时器和线程之间的区别 [英] Difference betwen timer and thread

查看:117
本文介绍了计时器和线程之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!每个人。你呢。我想问一下什么是 C#窗口形式中定时器和线程之间的区别。我已经从互联网上读到了一些答案。但我不会理解。有人可以用例子来解释我。



感谢所有兄弟的关注

解决方案

A计时器是一种通过发出应用程序响应并执行某些操作的事件来确保在特定时间或定期执行应用程序中的操作的方法。不应该假定Timer会导致事件在任何特定时间或间隔发生 - 事件可能在特定时间发出信号,但这并不意味着您的应用程序将能够在该时刻响应。

这有点像闹钟设定在07:00关闭 - 它会引发一个闹钟事件,你可以通过起床或按下打盹来回应按钮。



线程是处理的基本单位:每个线程都包含它自己的内存(以堆栈的形式,堆对所有线程都是通用的在一个应用程序中)一个应用程序通常会有多个线程 - 它总是至少有一个。多个线程可以同时运行(如果处理器中有足够的备用内核)或者 出现 可以同时运行,因为操作系统可以预先运行在它们之间切换以分享工作。

通常,多个线程用于移动任务,这些任务需要花费很长时间才能与直接与用户交互的线程移动,从而使它们保持响应。或者,可以同时对多个线程执行相同的任务,所有线程都使用不同的数据 - 因此,不是按顺序处理每个项目的循环,而是可以同时执行多个项目。

这有点像一个满是学生的课程:你可以让他们全都处理相同的问题(一个线程),或者你可以将任务分解成更小的块并将其传递给个别学生(多个线程)。 / blockquote>

定时器只是一个时钟进程,允许程序以固定的时间间隔接收中断,因此您可以执行某些操作;请参阅 http://msdn.microsoft.com/en- us / library / system.timers.timer(v = vs.110).aspx [ ^ ]。



线程是一个进程在程序的地址空间内独立运行,并且可以与其他线程交互(或不交互)。它允许您并行运行多个进程,这对于阻止长时间运行进程使程序看起来好像没有做任何事情特别有用。请参阅 http://msdn.microsoft.com/en-us/library/system.threading .thread.aspx [ ^ ]。

Hi! Everybody. How about you. I want to ask What is Difference Between Timer and Thread in C# window form . I already read some answer from the internet. But i don't understand very will. Someone can explain me with example.

Thanks you all of my brothers for your attention

解决方案

A timer is a means of ensuring that actions happen in your application at a specific time, or at regular intervals, by signalling a event that your application responds to and performs some action. It should not be assumed that a Timer will result in the event occurring at any specific time or interval - the event may be signaled at the specific time, but that doesn't mean that your application will be able to respond to it at that instant.
It's a bit like having an alarm clock that is set to go off at 07:00 - it raises an "alarm" event which you respond to by either getting up, or pressing the "snooze" button.

A thread is the "basic unit" of processing: each thread contains it's own memory (in the form of a stack, the heap is common to all threads within an application) and an application will often have more than one thread - it will always have a minimum of one. Multiple threads can operate at the same time (if there are sufficient spare cores available in your processor) or they can appear to operate at the same time because the operating system can preemptively switch between them to share out the work.
Very often, multiple threads are used to move tasks which take a long time away from threads which interact directly with the user, allowing them to remain responsive. Or, the same task can be performed on a number of threads at the same time, all using different data - so instead of a loop processing each item in sequence you can do a number of them at the same time.
It's a bit like having a class full of students: you can get them all working on the same problem (one thread) or you can break the task into smaller chunks and pass it out to individual students (multiple threads).


A timer is merely a clock process that allows your program to receive interrupts at fixed intervals, so you can perform some action; see http://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx[^].

A thread is a process that runs independently within a program's address space, and can interact (or not) with other threads. It allows you to run multiple processes in parallel, and is especially useful to stop long runing processes from making your program look as though it is not doing anything. See http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx[^].


这篇关于计时器和线程之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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