473,408 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

I have a problem with trackBar2 need help

The first problem is that i want to check if the variable file_info_trackBar2 is null or not.
So im checking if its null inside the StartWork function and if its null im doing trackBar2.Enable = false;

Now the backGroundWorking is starting to work and after few seconds file_info_trackBar2 isnt null.
So in the event: backGroundWorker1_DoWork im checking if file_info_trackBar2 isnt null != and its not so im doing trackBar2.Enable = true;
But i used a breakpoint on it and as its out after the trackBar2.Enable = true; im getting exception say:

Cross-thread operation not valid: Control 'trackBar2' accessed from a thread other than the thread it was created on

Whats that ? How can i solve it ? It happens only when im trying to make the trackBar2.Enable = true;

Second problem is inside the event: backGroundWorker1_DoWork again. I want that pb11 = new Bitmap(@"e:\radar003626.jpg"); instead this file it will make new Bitmap to the current file is on trackBar1. And in the function LoadPictureAt im getting the current file name on pictureBox1.Load(file_info_mouse_wheel[nIndex].FullName);
But how do i pass or use this file name on the pb11 = new Bitmap ?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Picturebox1_Fullscreen : Form
  14.     {
  15.         int nIndex1;
  16.         BackgroundWorker backGroundWorker1;
  17.         Bitmap[] myBitmaps;
  18.         Bitmap pb11;
  19.         FileInfo[] file_info_mouse_wheel;
  20.         string radar_images_download_directory;
  21.         private Bitmap[] file_info_trackBar2;
  22.         private bool _isDirty = false;
  23.  
  24.  
  25.         public Picturebox1_Fullscreen()
  26.         {
  27.             InitializeComponent();
  28.  
  29.  
  30.             backGroundWorker1 = new BackgroundWorker();
  31.             backGroundWorker1.WorkerSupportsCancellation = true;
  32.             backGroundWorker1.DoWork += new DoWorkEventHandler(backGroundWorker1_DoWork);
  33.             backGroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backGroundWorker1_RunWorkerCompleted);
  34.  
  35.             radar_images_download_directory = Options_DB.Get_Radar_Images_Download_Directory();
  36.             DirectoryInfo dir1 = new DirectoryInfo(radar_images_download_directory);
  37.             file_info_mouse_wheel = dir1.GetFiles("*.jpg");
  38.             trackBar1.Minimum = 0;
  39.             trackBar1.Maximum = file_info_mouse_wheel.Length - 1;
  40.             trackBar1.Value = file_info_mouse_wheel.Length - 1;
  41.  
  42.             // To check the pb11 new.....and to check how to check the file_info_trackBar2 if it null what to do \\
  43.  
  44.          //   if (file_info_trackBar2 == null)
  45.           //  {
  46.             //    trackBar2.Enabled = false;
  47.            // }
  48.  
  49.                 StartWork();
  50.             this.FormClosing += new FormClosingEventHandler(Picturebox1_Fullscreen_FormClosing);
  51.  
  52.  
  53.         }
  54.  
  55.         private void splitContainer1_Panel1_DoubleClick(object sender, EventArgs e)
  56.         {
  57.             this.Close();
  58.         }
  59.  
  60.         private void splitContainer1_Panel2_DoubleClick(object sender, EventArgs e)
  61.         {
  62.             this.Close();
  63.         }
  64.  
  65.         private void pictureBox1_DoubleClick(object sender, EventArgs e)
  66.         {
  67.             this.Close();
  68.  
  69.         }
  70.  
  71.         private bool LoadPictureAt(int nIndex, object c)
  72.         {
  73.  
  74.             bool bRet = false;
  75.  
  76.             if (nIndex >= 0 && nIndex < file_info_mouse_wheel.Length)
  77.             {
  78.                 if (c.Equals(trackBar1))
  79.  
  80.                     pictureBox1.Load(file_info_mouse_wheel[nIndex].FullName);
  81.                 nIndex1 = nIndex;
  82.                     bRet = true;
  83.  
  84.             }
  85.             if (file_info_trackBar2 == null)
  86.             {
  87.             }
  88.             else
  89.             {
  90.                 if (nIndex >= 0 && nIndex < file_info_trackBar2.Length)
  91.                 {
  92.                     if (c.Equals(trackBar2))
  93.                         pictureBox1.Image = file_info_trackBar2[nIndex];
  94.                     bRet = true;
  95.                 }
  96.             }
  97.             return bRet;
  98.  
  99.         }
  100.  
  101.         private void trackBar2_Scroll(object sender, EventArgs e)
  102.         {
  103.             StartWork();
  104.             LoadPictureAt(trackBar2.Value, sender);
  105.             pictureBox1.Refresh();
  106.  
  107.  
  108.         }
  109.  
  110.         private void trackBar1_Scroll(object sender, EventArgs e)
  111.         {
  112.             LoadPictureAt(trackBar1.Value, sender);
  113.         }
  114.  
  115.  
  116.         public PictureBox picturebox1(PictureBox pb1)
  117.         {
  118.             pictureBox1.Image = pb1.Image;
  119.             return pictureBox1;
  120.         }
  121.  
  122.         public string picturebox1_lastFile(string last_file)
  123.         {
  124.             pictureBox1.Load(last_file);
  125.             return last_file;
  126.        }
  127.  
  128.         private void backGroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  129.         {
  130.             int f = (int)e.Argument;
  131.             pb11 = new Bitmap(@"e:\radar003626.jpg");
  132.             myBitmaps = ImagesComparison.get_images_with_clouds(pb11);
  133.             if (this.backGroundWorker1.CancellationPending)
  134.             {
  135.                 e.Result = f;
  136.                 return;
  137.             }
  138.             file_info_trackBar2 = myBitmaps;
  139.             e.Result = f;
  140.             pb11.Dispose();
  141.             if (file_info_trackBar2 != null)
  142.             {
  143.                 trackBar2.Enabled = true;
  144.             }
  145.         }
  146.  
  147.  
  148.  
  149.         private void Picturebox1_Fullscreen_FormClosing(object sender, FormClosingEventArgs e)
  150.         {
  151.             //put in code here to show a message, or take some action
  152.             //if the bgw isBusy
  153.  
  154.             if (backGroundWorker1 != null)
  155.                 backGroundWorker1.Dispose();
  156.         }
  157.  
  158.         private void backGroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  159.         {
  160.             //display result
  161.  
  162.             //if previous bgw-operation cancelled
  163.             //start bgw again, so, that the current
  164.             //result is the current trackbar-value
  165.             if (this._isDirty)
  166.             {
  167.                 this._isDirty = false;
  168.                 StartWork();
  169.             }
  170.         }
  171.  
  172.         private void StartWork()
  173.         {
  174.  
  175.  
  176.                 //run bgw
  177.                 if (this.backGroundWorker1.IsBusy == false)
  178.                 {
  179.                     this.backGroundWorker1.RunWorkerAsync(this.trackBar2.Value);
  180.                     if (file_info_trackBar2 == null)
  181.                     {
  182.                         trackBar2.Enabled = false;
  183.                     }
  184.                 }
  185.                 else
  186.                 {
  187.                     //force re-run of bgw
  188.                     this._isDirty = true;
  189.                     //and cancel current action of bgw
  190.                     this.backGroundWorker1.CancelAsync();
  191.                 }
  192.  
  193.         }
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.     }
  202. }
  203.  

Thanks for helping.
May 23 '11 #1
0 881

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities,...
5
by: TrvlOrm | last post by:
HI There, I have been struggling with JavaScript code for days now, and this is my last resort! Please help... I am trying to create a JavaScript slide show with links for Next Slide,...
2
by: Chris | last post by:
Hi, I have a table with a field that should store date and time. The table column data type is datetime. I am trying Dim dt as datetime ...
6
by: jt | last post by:
I need to produce 1 character array from 3 others. I tried sprintf and it terminates on the first 0, null, 0x00 it sees in tmp data. All 3 args print out nice by themselves. By trying to make...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
0
by: David | last post by:
I have a problem that just cropped up with using an ImageList in my project I am using VB .NET 200 Problem: I have existing Form with 2 Image List controls. ImageList16 (for 16x16 Images) and...
0
by: rafaelgaucho | last post by:
Hi, I have a web service that return a Dataset. I want to get xml result from GetXml method of DataSet class like this: <xml... .> <MyDataSet xmlns="ssss\mySchema.xsd> <Table1>...
7
by: Tophurious | last post by:
So I posted this before, but got no answer. I found a way around it but now my backway is doing the same problem. Basically, in one of my get methods: Property Get H() As Double H = CalcH...
12
by: Xicer | last post by:
Hello everyone, this is my first post here so I will try to make it as clear as possible. Firstly i have a database with a single table named "albums" with the following fields: ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.