1
Reply

DataGridView and application freeze problem

Yusuf Avci

Yusuf Avci

Jan 29 2009 8:40 AM
7.4k

We have a problem in our Windows Forms Application. (.net 3.5)
We have many datagridviews in different forms but they have same datasource which is datatable. Datatable gets updated rapidly by socket messages in socket class. Then Datagridviews refresh automaticaly when datatable gets updated.

The problem is datagridviews freeze when scrolling or resizing etc... and it also freezes application.

we tried many difference solutions but they didnt work.

Any suggestions?

Thank you...

This is the sample of our program...

-----------Program.cs--------------------------------------------

        [STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Main());

        }

------------------Main.cs--------------------------------------------------------------------------------

public partial class Main : Form

    {

        public Main()

        {

            InitializeComponent();           

        }

        private void Main_Load(object sender, EventArgs e)

        {

            GridForm form1 = new GridForm ();

            form1.MdiParent = this;

            form1.Show();

        }

    }

----------------GridForm.cs-----------(DataGridView in this Form)-----------------------

public partial class GridForm : Form

    {

        public GridForm()

        {

            InitializeComponent();

        }

        DataView dv_datatable;

        private void GridForm _Load(object sender, EventArgs e)

        {

            dv_ datatable = new DataView(Global.DT);

            x_DataGridView.DataSource = dv_ datatable;

        }

     }

--------------Socketp.cs------------------------------------------------------------------------------------

public class Socketp

    {

      public Socketp ()

        {

            bwListener = new BackgroundWorker();

            bwListener.WorkerSupportsCancellation = true;

            bwListener.DoWork += new DoWorkEventHandler(bwListener_DoWork);

            bwListener.RunWorkerAsync();

        }

        void bwListener_DoWork(object sender, DoWorkEventArgs e)

        {

            SubscribeServer();

        }

public void SubscribeServer()

        {

            //Some Socket Codes

            IPEndPoint ipe = new IPEndPoint//…

            clientSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);           

            clientSocket.Connect(ipe); networkStream = new NetworkStream(clientSocket);  

            …        

            //Some Socket Codes

 

            while (clientSocket.Connected)

            {

                ///SomeCodes

            byte[] buffer = new byte[clientSocket.ReceiveBufferSize];

                ///SomeCodes

 

          DataRow rowx = Global.DT.NewRow();

          rowx ["ISLEM"] = fields[3];

          Global.DT.Rows.Add(rowx);//DataGridView is updated auto...

            }

        }

       

    }

 

Note : Form's DoubleBuffered attribute is true. DataGridView's attributes like AutoSize.. are false


Answers (1)