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

.NET (Core and Framework)

 
GeneralRe: String compare oddity Pin
Shameel19-Aug-11 5:57
professionalShameel19-Aug-11 5:57 
GeneralRe: String compare oddity [modified] Pin
PIEBALDconsult19-Aug-11 6:05
mvePIEBALDconsult19-Aug-11 6:05 
GeneralRe: String compare oddity Pin
Shameel19-Aug-11 9:32
professionalShameel19-Aug-11 9:32 
GeneralRe: String compare oddity Pin
PIEBALDconsult19-Aug-11 9:58
mvePIEBALDconsult19-Aug-11 9:58 
GeneralRe: String compare oddity Pin
Shameel20-Aug-11 8:28
professionalShameel20-Aug-11 8:28 
AnswerRe: String compare oddity Pin
PIEBALDconsult19-Aug-11 20:06
mvePIEBALDconsult19-Aug-11 20:06 
Questionplz brack my licence Pin
saqibali211918-Aug-11 8:09
saqibali211918-Aug-11 8:09 
QuestionHow to execute method n-times in a second? Pin
Tesic Goran17-Aug-11 21:03
professionalTesic Goran17-Aug-11 21:03 
Hi,

I have WindowsForms application where I should execute method n-times in a second. The method should be executed inside of its own separate thread. I use thread pool for that purpose.

UI contains text box where I enter the number of times of execution and button, which I click to start processing.

I've tried to use System.Windows.Forms.Timer but it works for smaller number of executions (~ up to 100). It works means for example 50 calls can be done in 1 second. When the number of calls is growing they can't be executed in 1 second. They need more and more time.

The code looks as follows:

C#
private int count = 0;
private int tps;

public Form1()
{
    InitializeComponent();
    ThreadPool.SetMaxThreads(500, 500);
}

private void button1_Click(object sender, EventArgs e)
{
    listBox1.Items.Clear();
    timer1.Enabled = true;

    tps = Int32.Parse(textBox1.Text);
    timer1.Interval = 1000 / tps;
    timer1.Start();
    label1.Text = "Start time: " + DateTime.Now.ToString("hh:mm:ss.fff");
    label2.Text = "End time: ";
}

private void timer1_Tick(object sender, EventArgs e)
{
    ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork));
}

private void DoWork(object stateInfo)
{
    count++;
    listBox1.Items.Add(count);

    if (count == tps)
    {
        count = 0;
        timer1.Stop();
        label2.Text = label2.Text + " " + DateTime.Now.ToString("hh:mm:ss.fff");
        timer1.Enabled = false;
    }
    label3.Text = listBox1.Items.Count.ToString();
}


Do you have an idea how I can resolve this issue?

Thank you in advance.


Regards,

Goran
AnswerRe: How to execute method n-times in a second? Pin
Shameel17-Aug-11 21:55
professionalShameel17-Aug-11 21:55 
GeneralRe: How to execute method n-times in a second? Pin
Tesic Goran17-Aug-11 22:28
professionalTesic Goran17-Aug-11 22:28 
AnswerRe: How to execute method n-times in a second? Pin
Pete O'Hanlon17-Aug-11 22:13
mvePete O'Hanlon17-Aug-11 22:13 
GeneralRe: How to execute method n-times in a second? Pin
Tesic Goran17-Aug-11 22:34
professionalTesic Goran17-Aug-11 22:34 
GeneralRe: How to execute method n-times in a second? Pin
Pete O'Hanlon17-Aug-11 23:57
mvePete O'Hanlon17-Aug-11 23:57 
AnswerRe: How to execute method n-times in a second? Pin
Luc Pattyn18-Aug-11 2:46
sitebuilderLuc Pattyn18-Aug-11 2:46 
Questionhttp://www.hotelsneardisneyland.biz/ Pin
lennonn1215-Aug-11 21:13
lennonn1215-Aug-11 21:13 
Question.NET Online Travel Guide Project Pin
Vanessa Vidal15-Aug-11 13:20
Vanessa Vidal15-Aug-11 13:20 
AnswerRe: .NET Online Travel Guide Project Pin
Not Active15-Aug-11 13:27
mentorNot Active15-Aug-11 13:27 
AnswerRe: .NET Online Travel Guide Project Pin
#realJSOP17-Aug-11 4:11
mve#realJSOP17-Aug-11 4:11 
AnswerRe: .NET Online Travel Guide Project Pin
Abhinav S17-Aug-11 8:23
Abhinav S17-Aug-11 8:23 
QuestionFile write times in .NET local drive vs. NAS drive Pin
MikeAngel15-Aug-11 11:07
MikeAngel15-Aug-11 11:07 
AnswerRe: File write times in .NET local drive vs. NAS drive Pin
Luc Pattyn15-Aug-11 11:39
sitebuilderLuc Pattyn15-Aug-11 11:39 
GeneralRe: File write times in .NET local drive vs. NAS drive Pin
MikeAngel15-Aug-11 12:10
MikeAngel15-Aug-11 12:10 
QuestionMessage Closed Pin
15-Aug-11 10:43
mwhardin15-Aug-11 10:43 
AnswerRe: Is Sql2Code.com a good developer tool? Would you use it? Pin
Richard MacCutchan15-Aug-11 22:34
mveRichard MacCutchan15-Aug-11 22:34 
GeneralRe: Is Sql2Code.com a good developer tool? Would you use it? Pin
mwhardin16-Aug-11 9:28
mwhardin16-Aug-11 9:28 

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.