Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Concurrency - Preferred approach to long running tasks

When there needs to be an I/O listener running throughout an applications lifetime, what concurrency model is preferred with C# 5.0 running on the 4.5 framework?

I've settled on the idea that a producer-consumer pattern would be best for handling what I receive, but what infrastructure should support it?

Would a simple Thread thread = new Thread(ThreadStart(method)) be advised? or perhaps a Task or Async/Await model would be preferred?

It is a bit of a quick fire question, but as I'm early in the design, I'd prefer to make sure the foundation is strong. My gut reaction coming from other languages is that a simple thread running in the background is best, but the plethora of parallel frameworks in C# has thrown me off course.

If of any relevance, the poll time in my application would be handled by the I/O read timeout.

Update:

The I/O I refer to is an FTDI device, where bytes may be pushed by the device to the PC at any moment, depending on the state of the on-board controller. As a result, I always need to be ready to pickup the data and process it. The API I'm using is based on the D2XX DLL provided by the FTDI vendor.

like image 879
BlackBox Avatar asked Feb 19 '14 16:02

BlackBox


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C language basics?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


1 Answers

If I interpret your "I/O listener" correctly, then you should just always have a continuous asynchronous read operation going. No thread is necessary.

like image 76
Stephen Cleary Avatar answered Oct 19 '22 23:10

Stephen Cleary