C# - Is It Sane To Use Thread.Sleep (int) In .NET Or Should I Use Another Method

Mar 16, 2011

I want to introduce a slight wait during some testing functions, to simulate a server call. Is it sane to use Thread.Sleep(int) to introduce the wait or is there a better method to have the server wait?

Note, I'll be pausing long enough for me to visually see a sufficient lag, even tho I don't expect to see such a delay in the actual app. This is for me to visualize the actual delay that could occur.

I plan on running this both in the VS2010 local debugger webserver and in IIS 7. I'm on .NET 3.5

View 2 Replies


Similar Messages:

Web Forms :: Use Thread.sleep Method For A Particular Thread?

Aug 27, 2010

I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.

View 5 Replies

C# - Lock Thread.sleep Not Working With .NET Thread?

Jun 25, 2010

I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having

bool isGoodPassword = (password == expected_password);

lock (this)
{
if (!isGoodPassword)
Thread.Sleep(2000);
}
I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.

View 4 Replies

Use Thread.sleep For No Reason And Explain It To Programmer?

Nov 10, 2010

While passing through code in our project I came across a web method that had this code at the end of it:

thread.sleep(6000);
return true;

Now, this was done so the jQuery ajax call from the client gets delayed and the ajax animation will show for a little bit longer. This is very wrong in my eyes. There shouldn't be this kind of connection between UI and server side. If he wants the animation to take longer he can use the setTimeOut function in the client side. Here is my problem: how can I explain to the programmer why this is so wrong? Not just because the client/server thing, but why ever call thread.sleep on a website?

View 6 Replies

C# - Async Function Thread.Sleep In Web Application?

Sep 8, 2010

I maintain a ASP.NET web application that causes a user's network connection to reset for several seconds when it executes a procedure. Therefore, the page request times out on the user's end as they never receive the web application's response (the connection dies before it gets the response packet).

To resolve this situation, I was contemplating having the ASP.NET page execute an asynchronous function that incorporates a Thread.Sleep(5000); // sleep for 5 seconds before executing the connection reset This way, the browser has 5 seconds to receive the page's response before their connection resets.

I have concerns with using Thread.Sleep and asynchronous functions in ASP.NET though. I've never attempted to do it before, so I'm unsure of the potential problems it may cause. Does anyone see potential problems with starting an asynchronous thread that contains a Thread.Sleep in an ASP.NET application?

View 3 Replies

Thread.Sleep() Blocking NetworkStream.BeginRead() Call Back?

Jul 7, 2010

I create a NetworkStream from a TCPClient, I then call BeginRead() followed by Thread.Sleep(60000).

It seems that the BeginRead call back function will only ever occur after Thread.Sleep() has completed. Is this expected behaviour?

What I was expecting was for the call back function to be carried out on a separate thread whenever it was ready and that the Thread.Sleep() on the current thread should have no affect on when/how the call back function runs...

I'm currently creating a VT100 terminal emulator, I wanted to created a method that would allow me to make the emulator sleep until a given string is found in the screen buffer. Initially I was trying to call WaitOne() on the IAsyncResult passed back from BeginRead() if the string was missing (this was to allow more data to pass into the system so that the check could then be carried out again until it was passed), after this failed I tried Thread.Sleep instead of WaitOne() but this blocked my BeginRead call back from firing and I'm now I'm starting to think everything is running from a single thread...

View 3 Replies

Cross-thread Operation Not Valid: Accessed From A Thread Other Than The Thread It Was Created On

Apr 2, 2010

I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-

Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.

i have tried invoke required but again got the same error. Sample code is below:

[code]....

View 1 Replies

C# - Looking For .NET Lock Thread Method?

Mar 30, 2010

I'm developing an ASP.NET forms webapplication using C#. I have a method which creates a new Order for a customer. It looks similar to this;
private string CreateOrder(string userName) {
// Fetch current order
Order order = FetchOrder(userName);[code]....

The problem here is, it is possible that 1 customer in two requests (threads) could cause this method to be called twice while another thread is also inside this method. This can cause two orders to be created.

How can I properly lock this method, so it can only be executed by one thread at a time per customer?

I tried;

Mutex mutex = null;
private string CreateOrder(string userName) {
if (mutex == null) { [code]....

This works, but on some occasions it hangs on WaitOne and I don't know why. Is there an error, or should I use another method to lock?

View 5 Replies

Parametarized Method Thread?

Mar 11, 2010

i'm trying to call a method with 3 parameters in a thread but i couldn't figure that out ..since it only accepts a non parametarized methods.

View 7 Replies

Thread Safety In Parameters Passed To A Static Method

Jan 10, 2011

Assuming a static method like below is called from ASP.NET page,can a different thread(b) overwrite the value of s1 after the first line is executed by thread(a)?If so, can assigning parameters to local variables before manipulation solve this?

public static string TestMethod(string s1, string s2, string s3)
{
s1 = s2 + s3;
....
...
return s1;
}

Is there are a simple way to recreate such thread safety related issues?

View 3 Replies

Visual Studio :: Debug A Multi Thread Program To See Local Variables Of Each Thread Using 2008

Jan 27, 2010

How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.

View 1 Replies

Architecture :: How Can Thread Update A Variable Shared With The Main Thread

Nov 24, 2010

I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.

Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.

Here is a quick example of how I use threading:

[code].....

View 3 Replies

What Are The Differences Between Currently Executing .NET Thread And Win32 Thread

Mar 24, 2010

I am reading the Asp.net security documentation on msdn.I come across these tow terms and get really confused.

# WindowsIdentity = WindowsIdentity.GetCurrent()

which returns the identity of the security context of the currently executing Win32 thread.

# Thread = Thread.CurrentPrincipal

which returns the principal of the currently executing .NET thread which rides on top of the Win32 thread.

View 1 Replies

Error While Adding Dynamic Data To An Existing Web Site - The Method 'Skip' Is Only Supported For Sorted Input In LINQ To Entities. The Method 'OrderBy' Must Be Called Before The Method 'Skip'.

Apr 13, 2010

I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error

"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "

View 2 Replies

C# - Set Thread As Background Or Not

Jan 2, 2011

I need an explanation regarding some advice I got on this site. I'm doing a newsletter sending app, and I have my mail sent in a seperate thread so the process doesn't slow down the whole web site. A couple of people advised me to set the threads IsBackground property to true. I did this, but was also courious about what this does, so I googled a bit.

As it turns out, setting the IsBackground property to true indicates that "it's okay if the process shuts down while this thread is still running.". Or as microsoft puts it "Any remaining background threads are stopped and do not complete." I don't know if I got this the wrong way but, wouldn't it be better to leave the IsBackground property to false, so that the spawned thread can complete its work regarding the main thread?

View 2 Replies

A Process In A Thread?

May 8, 2010

I want to execute a process, but after the process is done i would like to execute a query so i know this process is done.The process called ffmpeg is quite big so i start it and wait til its done with this coding:

ffmpeg.Start(); // start !

View 5 Replies

Thread ID From ThreadPool.QueueUserWorkItem?

May 18, 2010

after invoking an async method using ThreadPool.QueueUserWorkItem how do i lookup the assigned thread id?

View 4 Replies

Trying To Refresh A Page Through A Thread?

Apr 3, 2010

So basically here I am trying to wait for my server to connect to my website signaling it that its done and so the page needs to be refreshed(cause sql was updated). Thing is when I try to use the response/request in the thread it simply doesn't want to work.

Here the code

Code:

[code]....

Errors I am getting are:

1. If I have the headers clear thing there it gives requires integrated IIS pipes or something like that.
2.If I don't have the clear headers it says the headers were already sent.

View 13 Replies

Can A Client Be Considered As A Thread

Feb 24, 2011

Can we consider that two clients accessing the same method of a web service at the same time are two threads (with all problems involved...) ?Is it the same thing for methods in an asp.net web application ?

View 3 Replies

DataSource Controls :: Max Value Of Each Thread?

Mar 16, 2010

some details of image:

MessageID 14 and 19 are starting thread.

1 0 Yogendra1 Mishra 19 new msg
0 14 Yogendra1 Mishra 17 y
0 14 Yogendra1 Mishra 16 y
1 0 Yogendra1 Mishra 14 y

i want max messageid of each thread.

now my output should be.

19
17

View 5 Replies

C# - Does A PageAsyncTask Fire Off Its Own Thread

Mar 16, 2010

Does a PageAsyncTask fire off its own thread when used in a .aspx page?

View 1 Replies

C# - How To Progress Status From A New Thread

Jan 21, 2010

I am executing time consuming task in a new thread. ParameterizedThreadStart pts = new ParameterizedThreadStart(WorkingFoo); Thread thread = new Thread(pts);

The WorkingFoo executing the task and keeps track of the progress steps (it can return the total number of "steps" and the current step).

I want to display this information in a progress bar (simple div or ajax control, I don't mind).

I don't want, ofcourse, visually refresh the page that will display the progress. Also I want to reduce as much as possible the number of postbacks. So how do I do that? How to show the current progress from new thread on the web page? Also the page that shows the progress can be closed and re-opned and still get the current status.

View 1 Replies

How To Invoke A JavaScript Through A Thread

Feb 23, 2011

I have a thread that runs querying a DB and returning some values. If this values satisfyes a condition, I want to raise a message box (javascript alert) for the client side.

In my system, users can post some tasks in DB, and the thread is going to constantly query the database to check if user has things to do. If user has, the system must alert him through a message box.

I've done javascripts invokings with ClientScript.RegisterStartupScript, and Attributes.Add for buttons. But now I want to call the javascript functions (wich will alert the user that he has things to do) from the midle of a sub (that is executed in a thread), without a submit, load or click event. How can I do it?

View 2 Replies

Using MapPath From A Worker Thread?

Feb 24, 2010

I have a WCF service method that's running in a worker thread I spin from another method. I need to map a relative service app path ("~/Templates/a.template") to the physical path ("D:WebTemplatesa.template"), but I can't use HttpContext.Current.Server.MapPath because HttpContext.Current is null in a worker thread. How else can I reach MapPath method?

View 2 Replies

C# - Read A Value Being Manipulated In Different Thread?

Apr 15, 2010

I'm trying to read a static property from a static class, which is being modified from a different thread.

Basically I have this static class:

public static class Progress{
public static int currentProgress{get; set;}
}

and this thread manipulating the currentProgress:

private void Job(){
for(int i = 0; i<100; i++){
Progress.currentProgress = i;
Thread.Sleep(1000);
}
}

While this is running, I have a HttpHandler trying to access this progress (every few seconds), like so:

public void ProcessRequest(HttpContext context) {
context.Response.Write(Progress.currentProgress.toString());
context.Response.End();
}

But the currentProgress is set to it's initialvalue here, while the workThread is working, and only when done, is the currentProgress updated.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved