|
First, use codeblock formatting for code pieces this large. It helps reading.
If I read this correctly, you seem to set WindowState to Minimized in all cases
if ((State == FormWindowState.Maximized) || (State == FormWindowState.Normal))
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Show();
}
}
else if (State == FormWindowState.Minimized)
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Hide();
}
}
Also if you want the progress-form to follow main form's windowstate, could you simplify the logic and use mainform's events to minimize, normalize etc. the progress-form. For example in main form:
private void MainForm_SizeChanged(object sender, EventArgs e) {
if (this.WindowState == FormWindowState.Normal) {
this.frmProgressBar.WindowState = FormWindowState.Normal;
this.frmProgressBar.BringToFront();
} else if ...
}
Hope this helps,
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi Mika,
Thank you for your reply.
I typed it 'Minimized' in first if. It was my typing mistake.It should have been 'Maximized' instead.
I can't set the frmProgressBar's windowState from frmMain, because frmProgressBar is not a control in form frmMain, but a separate form whose methods (Hide and Show) are exposed through AggGlobals class (class which stores all application level variables and exposes common functionality). So I can't access it through frmMain.
But thank God, at last I got the solution. I set the 'Owner' property of frmProgressBar to frmMain (for that I had to store an instance of frmMain in AppGlobals) and set CheckForIllegalCrossThreadCalls = false in frmProgressBar constructor, and it worked !!! In vs 2003 it used to work without this setting but in vs 2005 MS has added a check for this. If you run it using ctrl + F5 the application run's perfectly fine, but while debugging i.e. F5 it is an issue.
Storing an object of frmMain in AppGlobals is a temporary solution and I think I will have to do this using reflection.
Cheers,
Prashant.
|
|
|
|
|
Glad you got it solved.
I understood that these are two separate forms. However form is just a class whereas other classes so if you want, you can store a reference to another form in main form using a variable that is type of frmProgressBar. This way you could fully control the frmProgressBar from the main form.
For example when showing progressbar, you could have a methods like following in the main form
private frmProgressBar barForm; <-- at form level
private void ShowProgress() {
barForm = new frmProgressBar();
barForm.Show();
...
}
private void UpdateProgress(int percentage) {
barForm.ProgressControl.Value = percentage;
OR PREFERRABLY
barForm.UpdatePercentage(percentage); <--- this method would update any necessary controls in frmProgressBar
...
}
private void EndProgress() {
barForm.Hide();
barForm = null;
...
}
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi all, I have added a bit more description to yesterdays post.Yesterday Mika had given me a solution, but for some reasons I can't do it that way because of some design constraints, and I have to do it this way only.
I have a form 'frmProgressBar', which is shown as popup using objfrmProgressBar.showDialog() from a class AppGlobals (AppGlobals.prpgressbar.show() method). frmProgressBar has a backgroundworker thread running, which keeps running till the processing in other forms is not compleated. I want to hide popup whenever the main form, on which other controls are loaded, is minimised and the popup is getting hidden also. But the problem is, when the main form is maximized, I want to show the popup form again. I checked !IsDestroyed for frmProgressBar which returns false, so the backgroundworker thread is still running, but the popup is not displayed in the foreground, only main form is shown. I tried Show(), BringToFront(), TopLayer = True, but nothing seems to work. Any help please.It is very urgent.
Following is my code :
bool bContinue = true;
public frmProgressBar(string Message)
{
InitializeComponent();
this.ShowInTaskbar = false;
lblMessage.Text = Message ;
backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler (backgroundWorker_RunWorkerCompleted);
}
//This is called when my main window is resized event us fired
private void setWindowStateAccordingToMainForm(FormWindowState State)
{
if (this.InvokeRequired)
{
setWindowState d = new setWindowState(setWindowStateAccordingToMainForm);
this.Invoke(d, new object[] { State });
}
else
{
if ((State == FormWindowState.Maximized) || (State == FormWindowState.Normal))
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Maximized;
BringToFront();
Activate();
}
}
else if (State == FormWindowState.Minimized)
{
if (!this.IsDisposed)
{
WindowState = FormWindowState.Minimized;
Hide();
}
}
}
}
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Close();
this.Dispose();
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
while (bContinue)
{
}
}
|
|
|
|
|
Few issues to point out:
1. The logic I suggested won't work if you use ShowDialog . This is because the code on the main form will wait until the dialog is closed. So if you want to use that approach, the main form must be in control all the time and frmProgressBar is only showing the current situation.
2. Of course the logic can be turned upside down so that the frmProgressBar is in control.
3. Another thing is owner. Do you specify any owner in Show or ShowDialog ? If not, try adding ShowDialog(this) (or replace this with instance of the mainform if needed.
And again, try to use:
codeblock formatting. It helps reading several lines of code.
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi,
I'm intrigued. If you have shown the progress form with ShowDialog() as your post suggests, how are you minimising the main form? Is it being done programmatically as I can't see how it could be done by user interaction?
I crafted a little test app which has a main form (Form1), a second form (AboutBox1) and a timer set to 5 seconds the function of which is to minimise and restore the main window. Both forms have the ShowInTaskBar property set to true.
If the app is run with about.Show(this) uncommented the two windows minimise and restore properly as a pair which simulates the action you desire in your app.
However try it when the second form is shown via ShowDialog()and you will find that the second form never reappears once it has been minimised.
I'm not sure why this is the case but the solution to your problem may be as simple as starting the progress form with Show rather than ShowDialog. Use the Show(this) version to ensure that the progress form stays on top of the main form.
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
timer1.Interval = 5000;
timer1.Enabled = true;
}
private void Form1_Shown(object sender, EventArgs e) {
AboutBox1 about = new AboutBox1();
about.ShowInTaskbar = true;
}
private void timer1_Tick(object sender, EventArgs e) {
if (this.WindowState != FormWindowState.Normal) {
this.WindowState = FormWindowState.Normal;
} else {
this.WindowState = FormWindowState.Minimized;
}
}
}
Alan.
|
|
|
|
|
Here is how I have implemented the above code:
When I want to show ProgressBar, I create a ProgressBar instance and start a new thread and show ProgressBar using objProgressBar.ShowDialog(). After this a backgroundWorker thread is started and kept running in the ProgressBar, which doe's nothing and just keeps on looping till bContinue (a bool) is false. When I say HideProgressBar() the variable 'bContinue' is set to false and the Progressbar is destroyed.
I have created a thread for running ProgressBar, because the main thread code will keep on working as is, and when I am done with the main thread processing, I will call HideProgressBar() which will destroy ProgressBar form.
These two forms are in separate projects, which are in the same solution file. MainForm is in a project, which is the Shell of my application and is the first form that is going to be loaded. After that, there will be other controls which will be loaded on this form, as and when required. I have used CAB which is provided by Microsoft.Practices.
I can't specify MainForm type in the ProgressBar's constuctor (as MainForm project's output is exe and not lib and the second thing is it would create cyclic reference). I stored the reference to MainForm (this) instance in the AppGlobals file and used this reference for subscribing to the mainForm's resize event using reflection, in the ProgressBar class. and I am getting the events also.
But when I try to set WindowState of ProgressBar, after I get the event of MainForm resized, the effect is not seen in the ProgressBar form. Also, if I click on some other application in taskbar, still the ProgressBar is shown, even if MainForm is minimized (or sometimes MainForm is in painting / hanged situation)
If I try to set Parent in the Progressbar form I get 'Top-level control cannot be added to a control'.
If I set Owner and add CheckForIllegalCrossThreadCalls = false, the problem is solved temporarily but the application starts behaving abnormally, like the main window after the aplication is started is minimised, or if I click on some other tabs in the main window, still the main Window gets minimised. So I think I will have to go with the solution without Owner property.
Could you please suggest a solution for this. Waiting for your reply
|
|
|
|
|
I have a program in our project named sales and stocks monitoring sytem in which it monitors the sales, products, and stocks.. it has stock in and stock out and it's sales has a charge and cash..
Anyone knows how to do this??
|
|
|
|
|
You should know that people in this forum are bored of these kinds of questions.
And answer to your question : Hire a programmer.
|
|
|
|
|
Yes thanks, I know how, so should anyone who dares to call themseleves a programmer.
If you don't then hire someone who does - and if they haven't got a proven track record, don't hire them, otherwise we will see THEM asking the same question on here.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
I have an executable application in C# that contains multiple .Net DLLs.
I should provide a SOA interface.
How do I start?
All I could find are articale about the SOA as an idea, but no samples,
nothing from the real thing
Cheers,
Gil
May the source be with you
|
|
|
|
|
Don't exactly understand what you mean by providing a SOA interface.
SOA is an architecture (Service Oriented Architecture) that can be used to separate logic based on the service provided to caller. So in other words, it's nothing technical only a 'guideline'.
The need to optimize rises from a bad design
|
|
|
|
|
Actually I didn’t understand as well
The customer asked a SOA interface for my product, quite a general statement.
From what I read about SOA, a SOA service should support any language, right?
So I wonder how technically to provide such as interface, any ideas?
Cheers
May the source be with you
|
|
|
|
|
This is a very large issue, so I'll be able to point out only few bullets. These are in random order so don't take this list as it would be prioritized:
- SOA is designed to separate different systems so that they can work independently and have only common interface (for example CRM vs ERP)
- it is mainly targeted for middle tier (this is not quite accurate, but gives the idea)
- client can be anything: UI, another system, service etc.
- client technology can be Microsoft based, Java or anything that is able to call web methods (again not literally accurate)
- it can be implemented in small scale (within a system) or large scale (between systems)
Based on the list above, you should create one or more systems that are working independently (depending how the customer sees this). However it is not efficient to use separate service approach in a small system since this could lead to repeated logic. The difference between systems should be 'natural'... Badly said What I mean for example is that it makes no sense to create a different, independent service for creating a customer and for updating the customer (of course the problem in the real world is not so obvious).
So what you should do, could be something like:
- discuss with the customer, how many systems should be created and what they are
- define services (web services if heterogenous or old MS clients) or WCF
- when defining a service, use interfaces for signature of a web method
- implement or move the logic on either side (middle-tier or client)
Also beware that if the application is currently running under one executable, breaking the logic to two separate layers may be a very large work (depending if the application is already designed for separation or not).
I hope that this helps you forward,
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Thanks for the detailed answer
You sure cleared some issues
I think WCF will be the winner
As for separated logic & executable - no prob
May the source be with you
|
|
|
|
|
You're welcome
The need to optimize rises from a bad design
|
|
|
|
|
Hi Gil,
I assume you are wanting to apply WCF to an existing application? Michele Bustamante has a good example here:
Hello Indigo[^]
This is taken from Chapter 1 of her book, Learning WCF. I do not own this book but it has had very good reviews.
The whole of Chapter 1 is available in PDF (and also at the link provided) and you can also download the source code for the book. The book was for VS 2005 .NET 3.0. However, she has also provided source for running in VS 2008/.NET 3.5.
Chapter 1 is actually an excellent step-by-step introduction to WCF where she uses one simple API ("Hello Indigo") and works through all of the different scenarios for using WCF with it. I've worked though a number of the examples, though I haven't yet tried the one described.
Kevin
|
|
|
|
|
Hi Kevin,
As I wrote to Mika, I'm not quite sure what my client ment by SOA interface
I need to ask my contact guy to ask the client for more info
I assume WCF is one way to provide the SOA concept, right?
Cheers
May the source be with you
|
|
|
|
|
Gil Shimer wrote: I assume WCF is one way to provide the SOA concept, right?
Yes. And if you're in the Microsoft world (which you most likely are if you're using C#) then this is the way to go. Once you've provided a WCF contract you're service will be accessible from any platform and any language.
However, if you're confined to .NET 1.x or 2.0 then web services is the way to go.
Kevin
|
|
|
|
|
Thanks
It looks like a solution
I'm back on the track
Cheers
May the source be with you
|
|
|
|
|
Hello everyone,
I have read a few WSDL documents and toturials, but find nothing covers how to add SOAP header for some web services port operations in WSDL file.
Does anyone have such referral documents or books?
thanks in advance,
George
|
|
|
|
|
Don't have any books in mind, but technically adding a SOAP header is described for example here.
SoapHeader Class[^]
I don't believe that you can add a header to a port (unless you write custom logic to handlers), but you can add header to web service and divide different services to different ports.
Hope this helps,
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi Mika,
My question is how to add SOAP header to some web methods in raw WSDL file, not modify the web services code to generate SOAP header as the link you referred shows.
Any comments or ideas?
regards,
George
|
|
|
|
|
Never done that before, but I would create a web service without header attributes and a copy of that web service with another name and with soap headers. Then, I would get the wsdl-files and compare them to see what has to be modified and how.
This isn't elegant aproach, but perhaps it would help ,
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi Mika,
I have already done what you described. But I think a more comprehensive document about how to add SOAP header and a sample would be greater! Any referral documents or forums/maillist to ask the question?
regards,
George
|
|
|
|
|