CFanatic

Go Back   CFanatic > Programming > C# Programming

add items in listview using System.Threading.Timer topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2011, 01:04 AM
Junior Member
 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shopno is on a distinguished road
| More
add items in listview using System.Threading.Timer

I want to add items in listview using threading timer that add items in listview in every 2 sec and this items come from MYsql db.I know that i should use invoke/begaininvoke to do this.But i dont understand how i can use invoke or begain invoke to add items in listview.Here is my code,

Code:
void PrepareTimers(List<int> _dataValues)
        {
            foreach (int dataValue in _dataValues)
            {
                ThreadingTimer timer = new ThreadingTimer(new TimerCallback(TimerAction), dataValue, 0, 2000);
            }

        }

void TimerAction(object flag)
{

           flags_string = flag.ToString();
            string sql = "SELECT msisdn,sms FROM sms_data_bankasia where flag = " + flags_string + " LIMIT 1";
            MySqlCommand comd = mycon.CreateCommand();
            comd.CommandText = sql;
            MySqlDataReader dtr = comd.ExecuteReader();
            try
            {
                if (mycon.State == ConnectionState.Open)
                {

                    if (dtr.Read())
                    {
                        msisdn_string = dtr["msisdn"].ToString();
                        sms_string = dtr["sms"].ToString();

                    }
                    else
                    {
                        flag = 0;
                        msisdn_string = "NO MSISDN FOR " + (flags_string);
                        sms_string = "NO MSISDN FOR " + (flags_string);
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

            dtr.Close();

            string[] listitem ={ msisdn_string, sms_string, flags_string };
            ListViewItem li = new ListViewItem(listitem);
            
            lstResult.Items.Add(li);
}
Any one can help me to do this?Any help can be great appritiated.

Last edited by shabbir; 11-02-2011 at 05:57 AM. Reason: Code Blocks
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ListView:how to colorize list view items in ListViewControl Sh@dow Win32 Programming 1 01-13-2011 06:53 AM
timer that stops a looping sound xzenon C# Programming 1 11-20-2010 10:27 AM
form controll threading Larsonator C++ Programming 0 10-04-2010 08:41 PM
clock with stopwatch or timer sonic05 C Programming 0 10-04-2010 10:31 AM
A listview with bigger font and space between items zspirit MFC Programming 0 08-31-2010 12:12 PM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.