|
Amlanjyoti Saikia wrote: LengthyOperationThread.Join(); When this code gets executed, main thread will be blocked until the worker thread finishes execution. Which means none of the UI messages will be processed and that might be the reason why you don't see GIF file animating.
I'd offload the work of creating report to to the WaitForm and do a ShowDialog() instead of Show() for displaying the WaitForm . You can modify WaitForm 's constructor so that you can pass necessary information required for report generation. This should fix both of your problems.
Best wishes,
Navaneeth
|
|
|
|
|
The report is basically a graphics object (not a physical file) for viewing and printing. It has to be created and displayed in the MainForm, so offloading the task to the WaitForm is not possible.
Also, Using WaitForm.ShowDialog() sort of solves the problem, and is not blocked in the main thread, but then I have no way of closing the WaitForm.
However, you were right about the main thread being blocked. I wanted it to be blocked, until report creation is complete. But I had wrongly assumed that WaitForm.Show() would run in its own thread, like a dialog box.
Thanks for pointing it out. I have the solution now.
|
|
|
|
|
1) Run the lengthy thread "Async". As is now, I can see how "createreport" is running on it's own thread, but not the lengthy operation.
2) Try[^] Form.Show(this) . Once the Window closes, focus within the app should move to it's owner (if the app has focus).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
1. Right on the money. CreateReport() is running on its own thread. But, WaitForm.Show() was not. The main thread blocked it from doing anything. And when as soon as it gets to do something, it was closed. I had stupidly assumed that Form.Show() runs on its own thread, like Form.ShowDialog(). Problem was I had no way of closing the DialogBox after CreateReport was done.
2. Taking care of the first problem took care of the second. Dark magic at work I say. .
Thanks for the idea of 'async' though. Couldn't use it because app has to run on .NET 3.5. So, created a new thread to show the WaitForm. Worked like a charm.
|
|
|
|
|
WRONG! You NEVER put any UI on the a seperate thread. What you did was put the UI on a seperate thread and then launched the long running work in yet another thread.
The way you've done it will appear to work fine but your code WILL run into problems every now and then that you can't replicate and will have a nasty time debugging. DO NOT PUT ANY UI IN A BACKGROUND THREAD!
Your long running work gets put on a background thread, such as using a BackgroundWorker, and then that frees up your UI thread to, well, update the UI. BackgroundWorker exposes a couple of events you can use to manage updating the UI without resorting to putting the UI in another thread.
|
|
|
|
|
Yep, my mistake. I ran into weird ThreadAbortExceptions and GDI+ errors.
Would really like to know why.
|
|
|
|
|
Well, the grossly simplified explanation is that Windows GDI library code that Graphics uses and all Forms and Controls use to draw themselves is not "thread-safe". The calls to various drawing and resource functions can step all over each other in very unsafe ways.
You can try to synchronize all of your resource and drawing calls, but the problem is that your application is not the only one using GDI when it's running, so it's nearly impossible to get a reliable multithreaded graphic routine running using GDI. The only reliable way to do multithreading GDI is to marshall all your control manipulation and drawing to methods on the UI thread.
|
|
|
|
|
My code was absolutely stupid and unnecessarily complicated. Brain fart...
This is the new code sample for anyone interested.
public class MainForm
{
WaitForm waitForm;
MainForm()
{
backgorundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bWorkerCompletedHandler_AllReports);
}
button1_ClickEventHandler(object sender, EventArgs e)
{
waitForm = new Waitform;
waitform.Show();
backgroundWorker1.DoWork += new DoWorkEventHandler(bWorkerHandler_Option1);
backgroundWorker1.RunWorkerAsync(ReportCategory1Object);
}
void bWorkerHandler_Option1(object sender, DoWorkEventArgs e)
{
Foo(e.Argument);
}
button2_ClickEventHandler(object sender, EventArgs e)
{
waitForm = new Waitform;
waitform.Show();
backgroundWorker1.DoWork += new DoWorkEventHandler(bWorkerHandler_Option2);
backgroundWorker1.RunWorkerAsync(ReportCategory2Object);
}
void bWorkerHandler_Option2(object sender, DoWorkEventArgs e)
{
Bar(e.Argument);
}
void bWorkerCompletedHandler_AllReports(object sender, RunWorkerCompletedEventArgs e)
{
backgroundWorker1 = new BackgroundWorker();
backgorundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bWorkerCompletedHandler_AllReports);
waitForm.Close();
}
void Foo(object Something)
{
}
void Bar(object AnotherThing)
{
}
}
|
|
|
|
|
hi to all..i need some help on how to access my ip camera in order to display stream on picturebox..please do help me... my camera has an ip 192.168.8.1..it can also be accessed through firefox by http://192.168.8.1 ..this is also my code,when i click the button, the picturebox should show the stream from the camera, but nothing happens..i am also using aforge.net library..
please check my code.. what do i missed? any help is greatly appreciated..thank you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video;
namespace cameratest
{
public partial class Form1 : Form
{
MJPEGStream stream = new MJPEGStream("http://192.168.8.1");
public Form1()
{
InitializeComponent();
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pictureBox1.Image = eventArgs.Frame;
}
private void Form1_Load(object sender, EventArgs e)
{
stream.NewFrame += new NewFrameEventHandler(video_NewFrame);
}
private void button1_Click(object sender, EventArgs e)
{
stream.Start();
}
}
}
|
|
|
|
|
You already asked this in QA: how to access an ip camera using c# and display stream on picturebox?[^] - don't post it in multiple places, it duplicates work and wastes time. That makes it rude!
Remember it's a weekend, so there are a lot less people here than normal so responses will take longer.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Sorry..i wont do it again..
|
|
|
|
|
hello every one i was a question about "property of network base software"
anybody can help me?
thank you....
|
|
|
|
|
Sorry but that makes no sense at all; please try rewording your question.
|
|
|
|
|
Excuse me,I want to learn about network software and how network software programing...?
-these software how to work?
and other questions...
|
|
|
|
|
First, you have to understand networking, which it doesn't sound like you do.
Read[^]
|
|
|
|
|
I have a OpenOffice Excel Sheet
that contains State,District,Taluka,Zone,Region and Territory
exprot these file into datatable or dataset
How it possible.
and while using open office in .net that contains any separate assembley.
Please give my full information.
|
|
|
|
|
You can read these into a dataset directly using OleDB; see these links[^] for some samples.
|
|
|
|
|
am using oledb
but am getting error
which assembly i need to use for OpenOffice.org 3.3
private void button1_Click(object sender, EventArgs e)
{
try
{
System.Data.OleDb.OleDbConnection MyConnection ;
System.Data.DataSet DtSet ;
System.Data.OleDb.OleDbDataAdapter MyCommand ;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\csharp.net-informations.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "TestTable");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}
}
I am getting Microsoft.jet.OLEDB not registered error
Please Help me For the above Problem
|
|
|
|
|
allasanthosh wrote: I am getting Microsoft.jet.OLEDB not registered error You need to download it from the Microsoft website[^].
|
|
|
|
|
The Jet provider won't work if you're running this code on a 64-bit machine. Jet is 32-bit only.
So, you either have to install the 64-bit ACE engine, downloadable from here[^] or go into your project properties and set the Target CPU to "x86" instead of "AnyCPU". That will force your code to run as a 32-bit application.
|
|
|
|
|
I am working with shape files using windows application
my requirements are
1.excel sheet contains state,district,taluka,region,zone,territory
- export data from excel sheet to datatable/dataset
-Create shape file
-create three columns in shape file automatically
-compare taluka-region
taluka-zone
taluka-territory
only maching values we have to store already created three columns
Please any body help me for this requirement.
Thanks
Santhosh
|
|
|
|
|
Help you with what?? What part of this are you having a problem with??
|
|
|
|
|
loading excel sheet data in data table
and i dont know creation of shape files
and total part of that question
|
|
|
|
|
Is there ANY part of this you have a clue about? If not, you're in trouble before you even get started.
You can start with this[^]
|
|
|
|
|
I have recently started to multithread my program and everything seems to work fine with the exception of a form I use to track the progress of data being transfered.
The Progress form is on the main thread, I send data to it as my program is processing it. The problem is that is does not appear on the form, I have used various methods to Invoke the thread but it just goes into a loop and never stops or just goes into oblivian. Some of the methods are as follows or similar:
public void UpdateStartTime(String text)
{
if (textBoxStartTime.InvokeRequired)
{
UpdateStartTimeCallback updateStartTimeCallback = new UpdateStartTimeCallback(UpdateStartTime);
Invoke(updateStartTimeCallback, new object[] { Text });
}
else
{
textBoxStartTime.Text = text;
}
}
and
public void UpdateStartTime(TextBox textBox, String text)
{
if (textBoxStartTime.InvokeRequired)
{
textBoxStartTime.Invoke(new Action<TextBox, String>(UpdateStartTime), new object[] { textBox, text });
}
else
{
textBoxStartTime.Text = text;
}
}
I also tried a delegate but it just does not see the other thread, I have verified the thread numbers are different and they're being used, it just doesn't make the connection.
Any ideas or suggestions will be greatly appreciated, thanks in advance.
Michael
modified 8-Feb-13 17:41pm.
|
|
|
|