Welcome Guest [Log In] [Register]
Welcome to USLS Computer Science Boards. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Any Discussion Sa Threading?; Available in Visual Studio .Net 2003&Up
Topic Started: Aug 24 2006, 05:08 AM (915 Views)
Shiegz
Member Avatar
"Teh" Sir Tan
Admin
I'm moving this topic under Microsoft Visual Studio.

The topic is about VB implementation of threads. Threads can be implemented in C++ as well as in Java but that's not the topic here. Please don't post anymore questions on how to implement threads in C++. Make another topic if want to discuss C++ threads in the appropriate forum.

If you don't know how to implement a "Hello World" program in VB, I suggest you study basic Visual BASIC first (err.. got a bit confused there :lol: ) before posting any questions.

Ok guys, let's make this discussion more meaningful and more informative.

Offline Profile Quote Post Goto Top
 
vincentg
Member Avatar

Alumni Moderator
Visual C# coding and syntax are the same. As far as I know, sa lab has only Visual C++ there (Last 2 yrs ko kita). Ang Threading nag uso sang nag gwa na ang .Net Technology.

But there are some coding or some aspect na gina code nila w/c acts like a Thread sa Visual C++/Visual Basic 6.0.

Pangita-on ko lng anay ang coding. But the best understanding sang Threading ara sa Visual Studio 2003 .Net & Visual Studio 2005 .Net

Based on my knowledge, sweldohanay sang C# na programmer if you doing Microsoft Stuff, is madako and of course expectation is high too.

www.Salary.com

Also try nyo surf this site, on how much is the offer sang sweldo if you know C#,VB.Net, etc

www.ComputerJobs.com
Sa States lng ni galing...

Sa pinas try nyo if manila ang target nyo
www.JobStreet.com

Offline Profile Quote Post Goto Top
 
Shiegz
Member Avatar
"Teh" Sir Tan
Admin
Threads have been around in other programming languages even before the .Net Technology. Maybe bag-o lang gid nila gin fully exploit ang threads sang MS Visual Studio.

Yeah, Visual Studio developers gets good pay but so does the legendary COBOL programmers .. that's off the topic though. :p

Guys plastar ta bi liwat ang discussion with these questions?

1. What are threads?
2. What are the advantages you can get from threads?
3. How are threads implemented in Visual Studio?
4. Sample applications with threads
5. Coding questions related to threads
Offline Profile Quote Post Goto Top
 
vincentg
Member Avatar

Alumni Moderator
From MSDN .Net 2003
Threads and Threading

Operating systems use processes to separate the different applications that they are executing. Threads are the basic unit to which an operating system allocates processor time, and more than one thread can be executing code inside that process. Each thread maintains exception handlers, a scheduling priority, and a set of structures the system uses to save the thread context until it is scheduled. The thread context includes all the information the thread needs to seamlessly resume execution, including the thread's set of CPU registers and stack, in the address space of the thread's host process.

The .NET Framework further subdivides an operating system process into lightweight managed subprocesses, called application domains, represented by System.AppDomain. One or more managed threads (represented by System.Threading.Thread) can run in one or any number of application domains within the same unmanaged process. Although each application domain is started with a single thread, code in that application domain can create additional application domains and additional threads. The result is that a managed thread can move freely between application domains inside the same unmanaged process; you might have only one thread moving among several application domains.

An operating system that supports preemptive multitasking creates the effect of simultaneous execution of multiple threads from multiple processes. It does this by dividing the available processor time among the threads that need it, allocating a processor time slice to each thread one after another. The currently executing thread is suspended when its time slice elapses, and another thread resumes running. When the system switches from one thread to another, it saves the thread context of the preempted thread and reloads the saved thread context of the next thread in the thread queue.

The length of the time slice depends on the operating system and the processor. Because each time slice is small, multiple threads appear to be executing at the same time, even if there is only one processor. This is actually the case on multiprocessor systems, where the executable threads are distributed among the available processors.

When To Use Multiple Threads
Software that requires user interaction must react to the user's activities as rapidly as possible to provide a rich user experience. At the same time, however, it must do the calculations necessary to present data to the user as fast as possible. If your application uses only one thread of execution, you can combine asynchronous programming with .NET remoting or XML Web services created using ASP.NET to use the processing time of other computers in addition to that of your own to increase responsiveness to the user and decrease the data processing time of your application. If you are doing intensive input/output work, you can also use I/O completion ports to increase your application's responsiveness.

Advantages of Multiple Threads
Using more than one thread, however, is the most powerful technique available to increase responsiveness to the user and process the data necessary to get the job done at almost the same time. On a computer with one processor, multiple threads can create this effect, taking advantage of the small periods of time in between user events to process the data in the background. For example, a user can edit a spreadsheet while another thread is recalculating other parts of the spreadsheet within the same application.

Without modification, the same application would dramatically increase user satisfaction when run on a computer with more than one processor. Your single application domain could use multiple threads to accomplish the following tasks:

Communicate over a network, to a Web server, and to a database.
Perform operations that take a large amount of time.
Distinguish tasks of varying priority. For example, a high-priority thread manages time-critical tasks, and a low-priority thread performs other tasks.
Allow the user interface to remain responsive, while allocating time to background tasks.

Disadvantages of Multiple Threads
It is recommended that you use as few threads as possible, thereby minimizing the use of operating-system resources and improving performance. Threading also has resource requirements and potential conflicts to be considered when designing your application. The resource requirements are as follows:

The system consumes memory for the context information required by processes, AppDomain objects, and threads. Therefore, the number of processes, AppDomain objects, and threads that can be created is limited by available memory.
Keeping track of a large number of threads consumes significant processor time. If there are too many threads, most of them will not make significant progress. If most of the current threads are in one process, threads in other processes are scheduled less frequently.
Controlling code execution with many threads is complex, and can be a source of many bugs.
Destroying threads requires knowing what could happen and handling those issues.
Providing shared access to resources can create conflicts. To avoid conflicts, you must synchronize, or control the access to, shared resources. Failure to synchronize access properly (in the same or different application domains) can lead to problems such as deadlocks (in which two threads stop responding while each waits for the other to complete) and race conditions (when an anomalous result occurs due to an unexpected critical dependence on the timing of two events). The system provides synchronization objects that can be used to coordinate resource sharing among multiple threads. Reducing the number of threads makes it easier to synchronize resources.

Resources that require synchronization include:

System resources (such as communications ports).
Resources shared by multiple processes (such as file handles).
The resources of a single application domain (such as global, static, and instance fields) accessed by multiple threads.
Threading and Application Design
In general, using the ThreadPool class is the easiest way to handle multiple threads for relatively short tasks that will not block other threads and when you do not expect any particular scheduling of the tasks. However, there are a number of reasons to create your own threads:

If you need a task to have a particular priority.
If you have a task that might run a long time (and therefore block other tasks).
If you need to place threads into a single-threaded apartment (all ThreadPool threads are in the multithreaded apartment).
If you need a stable identity associated with the thread. For example, you should use a dedicated thread to abort that thread, suspend it, or discover it by name.
Offline Profile Quote Post Goto Top
 
Chris Ongsuco
Nibble
theading reference - http://www.yoda.arachsys.com/csharp/threads/Threading in .Net
Offline Profile Quote Post Goto Top
 
batousai
Member Avatar
Pointer
Threading? Ano na sya man? Mr. VincentG daw damo kaman na balan....how can it help me as a learning programmer? isn't windows doing dat? how about processing messages and setting your process priority from low to high? is it considered threading? Im using both .NET and i want to process 5 database at the same time...how can i do it? :rolleyes:
Offline Profile Quote Post Goto Top
 
vincentg
Member Avatar

Alumni Moderator
There are some information that i have posted already regarding that question. Anyways, if you ask me, it really helps in making your program esp windows based app w/c has multiple process at the same time, run effeciently. The concept of it, is similar to the Timer Object.

Offline Profile Quote Post Goto Top
 
Chris Ongsuco
Nibble
@batousai

first, you can search "what is threading?" in google. second, it wont help you as a learning programmer...well at least not at the moment since you are still learning. Threading is an advance topic so i would suggest learning the basics of whatever your language preference first.

threading may not be the solution for processing 5 database at the same time. you might want to consider your application first - do you really need it and why? you might also want to consider the "how" questions like how often will this process run? like per transaction would mean that the system will update 5 databases at the same time?

threading wont speed up things. opening a thread is "heavy" and might take up lots of memory resources depending on how you use it.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Microsoft Visual Studio · Next Topic »
Add Reply