Click here to Skip to main content
15,914,014 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionProtecting Controls Pin
ProffK29-Dec-05 23:30
ProffK29-Dec-05 23:30 
QuestionInvalid DNS records Pin
fegf29-Dec-05 22:45
fegf29-Dec-05 22:45 
QuestionDon't need to appear Installer dialog window while installing/uninstalling windows application Pin
harikrishna_mit29-Dec-05 19:36
harikrishna_mit29-Dec-05 19:36 
AnswerRe: Don't need to appear Installer dialog window while installing/uninstalling windows application Pin
S. Akif Kamal30-Dec-05 21:30
S. Akif Kamal30-Dec-05 21:30 
QuestionOLEDB connection pooling Pin
faviochilo29-Dec-05 12:04
faviochilo29-Dec-05 12:04 
QuestionThreadStart Wrappers vs. State Pin
ProffK29-Dec-05 3:31
ProffK29-Dec-05 3:31 
AnswerRe: ThreadStart Wrappers vs. State Pin
S. Senthil Kumar2-Jan-06 5:13
S. Senthil Kumar2-Jan-06 5:13 
QuestionAborting thread in ThreadPool Class Pin
munshisoft29-Dec-05 0:46
munshisoft29-Dec-05 0:46 
Hi,
I am planning to use this approach please let me know if there is a problem in this approach..
The code compiles and works properly at runtime..but i am worried if there are issues which i have not anticipated..Please review the code.

Thanks and Best Regards,
Shahid

// This example shows how to create an Object* containing task
// information, and pass that Object* to a task queued for
// execution by the thread pool.
#include "stdafx.h"
#using

using namespace System;
using namespace System::Threading;

// TaskInfo holds state information for a task that will be
// executed by a ThreadPool thread.
public __gc class TaskInfo
{
// State information for the task. These members
// can be implemented as read-only properties, read/write
// properties with validation, and so on, as required.
public:
String* Boilerplate;
int Value;
Thread *tHandle;

// Public constructor provides an easy way to supply all
// the information needed for the task.
TaskInfo(String* text, int number)
{
Boilerplate = text;
Value = number;
tHandle=NULL;
}
};

public __gc struct Example
{
// The thread procedure performs the independent task, in this case
// formatting and printing a very simple report.
//
static void ThreadProc(Object* stateInfo)
{
try
{

//Do Always
TaskInfo *tInfo= (TaskInfo *)(stateInfo);
tInfo->tHandle = Thread::CurrentThread;

TaskInfo* ti = dynamic_cast(stateInfo);
Thread::Sleep(10000);
Console::WriteLine(ti->Boilerplate, __box(ti->Value));
}
catch(ThreadAbortException *Te)
{
Console::WriteLine(S"Thread Aborted by Main Thread{0}",Te->ToString());
}
}
};

int main()
{
try
{// Create an object containing the information needed
// for the task.
TaskInfo* ti = new TaskInfo(S"This report displays the number {0}.", 42);

// Queue the task and data.
if (ThreadPool::QueueUserWorkItem(new WaitCallback(0, Example::ThreadProc), ti))
{
Console::WriteLine(S"Main thread does some work, then sleeps.");

// If you comment out the Sleep, the main thread exits before
// the ThreadPool task has a chance to run. ThreadPool uses
// background threads, which do not keep the application
// running. (This is a simple example of a race condition.)
Thread::Sleep(1000);

//Abort the Thread started
ti->tHandle->Abort();

Thread::Sleep(15000);
Console::WriteLine(S"Main thread exits.");


}
else
{
Console::WriteLine(S"Unable to queue ThreadPool request.");
}
}
catch (...)
{
Console::WriteLine(S"Unknown Exception Occured in Main");
}
return 0;
}
;


Shahid Munshi
AnswerRe: Aborting thread in ThreadPool Class Pin
mikailcetinkaya3-Jan-06 20:35
mikailcetinkaya3-Jan-06 20:35 
Questionwriting windows service Pin
pankaj b28-Dec-05 21:40
pankaj b28-Dec-05 21:40 
AnswerRe: writing windows service Pin
Colin Angus Mackay29-Dec-05 0:26
Colin Angus Mackay29-Dec-05 0:26 
QuestionFundamentals Pin
HakunaMatada28-Dec-05 19:38
HakunaMatada28-Dec-05 19:38 
AnswerRe: Fundamentals Pin
MF28-Dec-05 19:47
MF28-Dec-05 19:47 
AnswerRe: Fundamentals Pin
Colin Angus Mackay29-Dec-05 0:20
Colin Angus Mackay29-Dec-05 0:20 
GeneralRe: Fundamentals Pin
ProffK29-Dec-05 4:46
ProffK29-Dec-05 4:46 
QuestionIs there an Event Fired when a Disk is inserted Pin
fabertroll28-Dec-05 18:26
fabertroll28-Dec-05 18:26 
AnswerRe: Is there an Event Fired when a Disk is inserted Pin
Dave Kreskowiak29-Dec-05 5:34
mveDave Kreskowiak29-Dec-05 5:34 
GeneralRe: Is there an Event Fired when a Disk is inserted Pin
fabertroll29-Dec-05 5:42
fabertroll29-Dec-05 5:42 
QuestionManaged File Writing and Classes Pin
YouGetThat28-Dec-05 17:34
YouGetThat28-Dec-05 17:34 
Questionhow to customize MS OFFICE using WINDOWS API's..? Pin
pradpb99927-Dec-05 22:18
pradpb99927-Dec-05 22:18 
AnswerRe: how to customize MS OFFICE using WINDOWS API's..? Pin
Colin Angus Mackay29-Dec-05 0:24
Colin Angus Mackay29-Dec-05 0:24 
QuestionDelegates and Asynchronous Calls Pin
HakunaMatada27-Dec-05 17:14
HakunaMatada27-Dec-05 17:14 
AnswerRe: Delegates and Asynchronous Calls Pin
tarasn30-Dec-05 3:17
tarasn30-Dec-05 3:17 
Questionmaking combobox scrollbox wider Pin
plukje26-Dec-05 23:37
plukje26-Dec-05 23:37 
AnswerRe: making combobox scrollbox wider Pin
S. Akif Kamal27-Dec-05 3:29
S. Akif Kamal27-Dec-05 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.