Programming Tutorial On The Way

free online programming resource on dotnet, csharp, web related topics

Visual Basic specifies a Boolean’s default values as zero for False and -1 for True. You may save and set the value of a check box, based on the absolute value of a Boolean variable, as these correspond to the intrinsic constants vbUnchecked and vbChecked:
Read the rest of this entry »

Popularity: 7% [?]

Unlike the Windows 95 common controls, the standard list box doesn’t have a horizontal scrollbar when list items are too wide to fit within the list box. Fortunately, it’s not hard to direct a listbox control to display a horizontal scrollbar. Add this code to a form’s Load event. It fills a list box with 100 long strings and calls SetHScroll to show a horizontal scrollbar in the list box:

Private Sub Form_Load()
	Dim i As Integer
	For i = 1 To 100
		List1.AddItem CStr(i) & _
			" bottle(s) of beer on the wall."
	Next i
	SetHScroll Me, List1, List1.List(0)
End Sub

Read the rest of this entry »

Popularity: 7% [?]

Setting an element in an array of option buttons to True is easy. Click on the option button, or use this code:

OptionArray(ThisOne) = True

ThisOne is the Index of the member you want to be selected. Getting the True member of an option array is not so simple. Because you need to perform this kind of task in almost any reasonably complex program, adding this function to your code library or generic module simplifies the task. You don’t need to know the array size in advance:
Read the rest of this entry »

Popularity: 7% [?]

When attempting to determine which option buttons a user has selected from an array of option buttons, use this code instead of using an inefficient If-Then construct:

intSelectedItem = Option(0).Value * O - _
    Option(1).Value*1 - Option(2).Value * 2

Read the rest of this entry »

Popularity: 7% [?]

The stylish digital photo frame

Digital Photo Frame
I am already has a digital camera, and now I am looking for digital photo frame. Well, I think many people have known this frame or maybe you already has one at your home. I like this frame because it’s more convenient and it looks beautiful at my home and my office. Beside that, it’s an ideal gift for any occasion. Whether celebrating a wedding, birthday party or any happy event, it’s the perfect present as well as a fantastic way to display and remember the occasion. The slideshow function of the frame as it is like having an endless number of pictures at once. And I finally get my digital photo frame at Digitalframez.com.au.
Read the rest of this entry »

Popularity: 28% [?]

For threads that are manually created via the Thread class, you can call the Join method to wait for a thread to finish. This works well when you need to wait for all threads to finish processing before an application terminates. Unfortunately, the thread pool threads do not have a Join method. You need to make sure that all threads in the thread pool have finished processing before another thread terminates or your application’s main thread terminates.

Use a combination of the ThreadPool methods — GetMaxThreads and GetAvailableThreads — to determine when the ThreadPool is finished processing the requests.
Read the rest of this entry »

Popularity: 35% [?]

Synchronizing the Reading and Writing of a Resource Efficiently

When you have a resource that is shared by multiple threads, you need to provide exclusive access to this resource when a thread is writing to it. However, you do not want the overhead of providing exclusive access to this resource when multiple threads are only reading from it. You want to allow one thread to access a shared resource only if it is writing to it, but you also want to allow multiple threads to read from this resource. While multiple threads can read from a resource, a write operation cannot occur while any thread is reading from this resource.

Example below uses the ReaderWriterLock class from the System.Threading. The ReaderWriterLock is optimized for scenarios where you have data that changes infrequently but needs protection for those times when it is updated in a multithreading scenario. To illustrate, the GradeBoard class represents a board where an instructor will post the grades students received from a class. Many students can read the grade board, but only the instructor can post a grade (write) to the grade board. Students will not, however, be able to read from the board while the instructor is updating it.
Read the rest of this entry »

Popularity: 32% [?]

The ThreadPool is a great way to perform background tasks without having to manage all aspects of the thread yourself. It can be handy to know when the ThreadPool itself is going to become a bottleneck to your application, and the GetAvailableThreads method can help you. However, you might want to check your application design if you are consistently using this many threads as you might be losing performance due to contention or context switching. Queuing up work when the ThreadPoolM is full simply queues it up for execution once one of the threads comes free; the request isn’t lost, just postponed.

In this example, your application will be creating many threads from the thread pool. When creating a thread from this pool, you want to be informed as to whether a thread in the pool is available or if none are available, and the request for a new thread will have to be queued. Basically, you want to know whether a thread is available for immediate use from the thread pool. Use the ThreadPool.GetAvailableThreads method to get the number of worker threads currently available in the ThreadPool to determine whether you should queue another request to launch another thread via ThreadPool.QueueUserWorkItem or take an alternate action. The Main method calls a method (SpawnManyThreads) to spawn lots of threads to do work in the ThreadPool, then waits for a bit to simulate processing.
Read the rest of this entry »

Popularity: 41% [?]

« Previous Entries