hi friends
i have made 1 application in c#,,,,,,,,,,,,,,,it has lot of loop
so when it are doing process in loop
my window application form hang and dumb
so i cant access any button of form
????????????????????????
how can i solve it
????????????????????????????????????
Thanks in Advance

Its hard to tell what can be wrong - obviousely the code hangs somewhere in between, in some loop. That means that the code came into an infinitive loop - it will circle forever. Why? I cannot tell you... but can you please share you code here, so we can help you find the error in the code?

Mitja

but my code has not any problem it work fine..................
but only problem that when my code processing(code has lot of loops) i cant access my form controls why??????????or how can i access it

The loops have so much work, that the form is not responding. Thats is whole the code is going on in one thread. There are two solutions, or to use BackGroundWorker, or you put the loops into another thread, so the main thread of the form will be free of that code, and so it will be responsive.
The last option (of creating new thread) is easy and faster for beginners.

thanks buddy ,,,,,,,,,,,but i cant access my from control in thread or background worker so i was confused and want new option ,,,but you tell me same solution........................how can access my from control in thread or background worker ????

my from? Are you talking about form?
And I really dont understand what are you saying.
Look, where do you havea code of those loops? It is in Form1 (or in some other form, it doesnt matter).

What you have to do is the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Jan09Exercise
{
    public partial class Form1 : Form
    {
        delegate void MyDelegate(string msg);
        public Form1()
        {
            InitializeComponent();
            labelShow.Text = "";
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(DoingTimeConsumingStuff));
            thread.Start();
        }

        private void DoingTimeConsumingStuff()
        {
            for (decimal i = 0.0001M; i < 1000000000; i++)
            {
                UpdatingMyControl(i.ToString());
            }
        }

        private void UpdatingMyControl(string strValue)
        {
            if (this.labelShow.InvokeRequired)
                this.labelShow.Invoke(new MyDelegate(UpdatingMyControl), new object[] { strValue });
            else
                labelShow.Text = strValue;
        }      
    }
}

CAREFULY look into this example, which shows three important things:
1. creating a new thread
2. on this thread then runs a long time consuming loop (without a new created thread the form would be unresponsive
3. Use of delegates, which are required to update the control while threads are busy.

What you have to do is to accomodate this code to yours.

Hope it helps,
Mitja

ohhhhhhhhhhhh yes i done it!!!!!!!!!!!!!
but dear your code method is so long i was already know it.........i want small method which i got from google and i done solved my problem
Thanks Alot 4 your time :p

i want this small method which you got from google and you solve your problem

Edited 3 Years Ago by sumoncse05

This article has been dead for over six months. Start a new discussion instead.