|
Hello,
I need to create a child process in C#. The main process should wait until the child process is done. The execution goes in this order:
/////////////////////////////////
parent process executes some code
parent process creates a child process and goes to sleep
child process executes some code
child process is done executing the code
parent process wakes up
parent process continues execution
///////////////////////////////////
I am looking for some simple implementation i.e. something like the fork() system call available in the C programming language. I don't want to create a new Thread. Any ideas how to achieve this result?
Thank you!
Best,
Martin
|
|
|
|
|
|
If the parent is only going to sleep while the child works, why bother having the child?
martingeorgiev wrote: I don't want to create a new Thread
You can't create an old one.
|
|
|
|
|
It sounds like a great plan: have fun, let others do the work.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
That's what delegates are for.
|
|
|
|
|
I tried using delegates. It is giving me the same error message. see my other post below.\
Thanks!
|
|
|
|
|
|
My code goes like this:
1. gets the indices of the selected items on the form ( ListView ).
2. the form gets updated.
3. restores the selection on the selected items.
Now, if I process the code as stated above, when trying to restore the selection, I get an error message saying that the index is not available. However, if I put a message box right before the selection code ( maybe to slow down ... I don't really know what the difference is ) kicks in, everything works fine.
What might be causing this problem? I have been trying to figure this out for quite a long time.
Thanks a lot!
Best,
Martin
|
|
|
|
|
I've never used a ListView. Are you saying it loses state when the Form is updated? That doesn't make any sense to me. You should find out what causes it before trying to find a work-around.
|
|
|
|
|
The main application fetches data from the database. How to display a progress bar while this fetching is in progress?
|
|
|
|
|
Well, you know that you want to use a BackgroundWorker (your thread title gives this away). This has an event to report the ProgressChanged . Basically, you need to call ReportProgress from your worker thread, and this raises the ProgressChanged event where you can update the progress bar. When you instantiate your background worker, you have to set WorkerReportsProgress to true to be able to report the progress.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
problem is :it displays the progress bar after it has finished fetching !!
|
|
|
|
|
when user clicks an item in the toolbar , the main thread fetches the corresponding data. Meanwhile the background worker thread is supposed to show progress . But instead it is activated only after the fetching is done. any suggestions on how to improve this?
A snippet of my code is as given below:
< my code>
private void toolStripMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
bwProgress.RunWorkerAsync();
}
private void bwProgress_DoWork(object sender, DoWorkEventArgs e)
{
// update the progress bar
for (int i = 0; i <= 100; i+=10)
{
bwProgress.ReportProgress(i);
}
}
private void bwProgress_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
toolStripProgressBar1.Visible = true;
toolStripProgressBar1.Value = e.ProgressPercentage;
}
private void bwProgress_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
toolStripProgressBar1.Style = ProgressBarStyle.Blocks;
toolStripProgressBar1.Value = 100;
}
|
|
|
|
|
The problem with your code sample here is that it runs too fast for you to see the progress changed event in action. You need a lengthy operation to see the effect, so youy should really pause the execution between each iteration through the loop.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
That would suggest you're using it in the wrong way. Here's a small sample demonstrating how to update a progress bar while a loop is incrementing,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace SampleBackgroundWorker
{
public partial class MainForm : Form
{
private BackgroundWorker _worker = new BackgroundWorker();
private static readonly object SyncLock = new object();
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_worker.WorkerReportsProgress = true;
_worker.ProgressChanged += new
ProgressChangedEventHandler(ProgressChanged);
_worker.DoWork += new DoWorkEventHandler(DoWork);
_worker.RunWorkerAsync();
}
void DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 10; i++)
{
lock (SyncLock)
{
Monitor.Wait(SyncLock, 1000);
}
_worker.ReportProgress(i * 10);
}
}
void ProgressChanged(object sender, ProgressChangedEventArgs e)
{
barProgress.Value = e.ProgressPercentage ;
}
}
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Little demo in this tip[^]
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Hi,
I am getting the error while saving the excel work sheet in the windows 2003 server. Same piece of code is working fine in my local desktop. below is the error message. Given required permissions to the folder to IUSR, IWAM, Network service and ASP.NET accounts. Though i am getting the below error
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a.
Getting error in the below piece of code-
Line 1005: Microsoft.Office.Interop.Excel.ApplicationClass objApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
Any help is appriciate.
Thanks In Advance.
|
|
|
|
|
Take a look at Considerations for server-side Automation of Office[^].
It seems that M$ do not advise doing this.
I found the link above by pasting your entire error message into the Google search box. Give it a go. There are loads of people out there that think they have a solution. Whether any of them actually resolve the problem, you'll have to find out for yourself.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
hi my friends
i have an application that i designed it myself with c#.
i want to change it to work in a system with multi phone number in central phone device.
normally with central devices you can not achieve the caller id or at least i can't. so please someone if know the solution for this problem guide me in right direction or give me a sample.
thank you
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
hello,
I am using Threads in my app that runs a process of writing data on Pole(Customer)-Display Hardware Device. Now this thread calls every single second. And what is happening is that the 1st thread have'nt write its content completely and 2nd thread called and it disturbs the 1st one as well. I have'nt played much with Threads, Can i make thread to wait in a way that If a thread is called it should check 1st that if any other thread already running the same method, it should wait for that thread to end.
Thanks in Advance,
Asfand
|
|
|
|
|
Synchronization in multithreading environments can be done with semaphores[^] and mutexes[^].
Here[^] is a mutex example.
I have no smart signature yet...
|
|
|
|
|
yes you can configure the propertiese of your thread to wait for complete execute befor newest thread be running.
the method is join() (ThreadName.join()).
i hope this method help you to solve your problem.
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
thnx alot, it worked
|
|
|
|
|
It seems to me that if the writing threa is busy, you swould be better advised to ignore the current write request, and just write when the thread isn't busy. Eventually, you're going to deadlock the machine because you're waiting for the thread to finish.
You may even want to have the timer adjust its interval so that there's less of a chance of the thread being in a busy state.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|