Gomathi Palaniswamy

Gomathi Palaniswamy

  • NA
  • 3.5k
  • 2.2m

threading

Jul 28 2010 2:27 AM
Sir/Madam

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

namespace AQP_Network
{
    public partial class AQP_Network: Form
    {
        //Operations opr = new Operations();
      //  System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
        bool editbuttonclick = false;
      
        ThreadStart job;
        Thread th;
        Image background = Image.FromFile(@"G:\ieee projects\AQP-Network\123.jpg");
        Image red_car = Image.FromFile(@"G:\ieee projects\AQP-Network\obj1 copy.gif");
        Image red_car1 = Image.FromFile(@"G:\ieee projects\AQP-Network\fantasy_133.gif");
        int x = 6, y = 146, m = 3;
        int x1 = 980, y1 = 9, m1 = 3;
        int count = 0, count1 = 0, count2 = 0, count3 = 0;
        public AQP_Network()
        {
            Text = "Simple Animation";
            CenterToScreen();

            job = new ThreadStart(Threadjob);
            th = new Thread(job);

            th.Start();

            ThreadStart job1 = new ThreadStart(Threadjob1);
            Thread th1 = new Thread(job1);
            th1.Start();
            Invalidate();

            //enabling double-buffering to avoid flicker
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            this.WindowState = FormWindowState.Maximized;
        }
        void OnPaint(Object sender, PaintEventArgs e)
        {
            if (count < 70)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                        y -= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x += 2;
                        y +=1;
                        count++;
                    }

                }
              
            }
            if (count >= 70 && count < 145)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                        y -= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x += 2;
                        y += 2;
                        count++;


                    }

                }

             
            }
            if (count >= 145&& count <250)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                        y -=1;
                        m = m + 3;
                    }
                    else
                    {
                        x += 1;
                        y += 3;
                        count++;


                    }

                }

    
            }
            if (count >= 250 && count < 310)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                      
                        m = m + 3;
                    }
                    else
                    {
                        x += 1;
                     
                        count++;


                    }

                }

            }

            if (count >= 310 && count < 455)
            {

           
                if (x < Width)
                {
                    if (count == m)
                    {
                      
                        y -=1;
                        m = m + 3;
                    }
                    else
                    {
                     
                        y-= 1;
                      
                        count++;

                    }

                }


            }
            if (count >= 455 && count < 500)
            {

                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                        y -= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x += 1;
                        y -= 1;
                     
                        count++;

                    }

                }

            
            }
            if (count >=500 && count <650)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                        y -= 4;
                        m = m + 5;
                    }
                    else
                    {
                        x += 1;
                        y += 1;
                        count++;

                    }

                }

            }
            if (count >=650 && count <809)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                      
                        y -= 1;
                      
                        m = m + 3;
                    }
                    else
                    {

                        y -= 1;
                      
                        count++;

                    }

                }

             
            }
            if (count >= 809 && count <950)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                        x += 1;
                        y -= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x += 1;
                        y -= 1;
                     
                        count++;

                    }

                }

             
               
            }
            if (count >= 950 && count < 1300)
            {
                if (x < Width)
                {
                   
                    if (count == m)
                    {
                        x -= 1;
                        y+= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x -= 1;
                        y+=1;                   
                        count++;

                    }

                }           
            }
            if (count >= 1300 && count <1610)
            {
                if (x < Width)
                {
                    if (count == m)
                    {
                       
                        y+= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x -= 1;                   
                        count++;

                    }

                }              

            }
            if (count >=1610 && count<1825)
            {
                if (x < Width)
                {
                    if (count == m)
                    {

                        y -= 1;
                        m = m + 3;
                    }
                    else
                    {
                        x -= 1;

                        count++;

                    }

                }             

            }
            if (count >= 1825)
            {
                x = 6; y = 146; m = 3;
                count = 0;
            }         
            Graphics g = e.Graphics;
            DrawStuff(g);
            Invalidate();

        }

        void OnPaint1(object sender, PaintEventArgs e1)
        {
        }

        void DrawStuff(Graphics g)
        {
            g.DrawImage(background, 0, 0);
            g.DrawImage(red_car, x, y);
            Invalidate();

        }
        void DrawStuff1(Graphics g1)
        {
          
            g1.DrawImage(red_car1, x1, y1);
            Invalidate();
        }
        void Threadjob()
        {
            Paint += new PaintEventHandler(OnPaint);
            Invalidate();

        }
        void Threadjob1()
        {
            Paint+=new PaintEventHandler(AQP_Network_Paint);
          //  Paint += new PaintEventHandler(OnPaint1);
            Invalidate();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

        }
        private void AQP_Network_Paint(object sender,PaintEventArgs  e)
        {
            if (count1 < 350)
            {
                if (x1 < Width)
                {
                    if (count1 == m1)
                    {
                        x1 -= 1;
                        y1 += 1;
                        m1 = m1 + 3;
                        count1++;
                    }
                    else
                    {
                        x1 -= 1;
                        y1 += 1;
                        count1++;
                    }
                }
            }
            if (count1 >= 350 && count1 < 451)
            {
                if (x1 < Width)
                {
                    if (count1 == m1)
                    {
                        x1 += 1;
                        y1 += 1;
                        m1 = m1 + 5;
                        count1++;
                    }
                    else
                    {
                        x1 += 1;
                        count1++;

                    }

                }

            }
            if (count1 >= 451 && count1 < 540)
            {
                if (x1 < Width)
                {
                    if (count1 == m1)
                    {
                        x1 += 1;
                        y1 += 1;
                        m1 = m1 + 5;
                        count1++;
                    }
                    else
                    {
                        x1 += 1;
                        count1++;

                    }

                }
            }

            Graphics g1 = e.Graphics;
            DrawStuff1(g1);
            Invalidate();
        }
    }
}

in above program the second thread is not working properly.what mistake i have done in this???


With Regards,
Gomathi.P

Answers (1)