|
Yes there is but I wouldn't recommend it. You should put long running process in a separate thread and not in a button click event for several reasons. It will make your GUI responsive, the code will be designed and structured in much more better way.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
So, basically without re-working the whole app there is no chance?
Just to clarify, I have been reading up on Threads and from what I read it doesn't seem to be that easy to work with but it doesn't seem that diffcult though. So, I would just have to declare a new Thread, call this Thread in the button event and away it goes?
I'll try and move the stuff around a bit to see what I can do about this. Hopefully I get it to work with no hastles.
Thanks mate for the reply
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Kwagga wrote: So, basically without re-working the whole app there is no chance?
You can use Application.DoEvents() but I would highly discourage from doing so.
Kwagga wrote: Just to clarify, I have been reading up on Threads and from what I read it doesn't seem to be that easy to work with but it doesn't seem that diffcult though. So, I would just have to declare a new Thread, call this Thread in the button event and away it goes?
Threads aren't very easy topic but they are quite powerful and it's worth studying it. If you need to do simple work you can use BackgroundWorker class. Here is a more in depth explanation about threading concepts: Threading in C#[^]
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Hi Giorgi. I ahve moved the code into a new thred but I get an error on the progressbar. Error details as below.
System.InvalidOperationException was unhandled<br />
Message="Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on."<br />
Source="System.Windows.Forms"<br />
StackTrace:<br />
at System.Windows.Forms.Control.get_Handle()<br />
at System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, Int32 lparam)<br />
at System.Windows.Forms.ProgressBar.set_Maximum(Int32 value)<br />
at NomConv.Form1.RunExcel() in C:\Documents and Settings\mumbleb\My Documents\Visual Studio 2008\Projects\NomConv\NomConv\Form1.cs:line 118<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()<br />
InnerException:
Now, this is what I'm doing. I'm calling the Thread in the button event as below.
private void btnRun_Click(object sender, EventArgs e)
{
Thread excelrun = new Thread(RunExcel);
excelrun.Start();
lblPercent2.Visible = true;
lblRecordProcessed.Visible = true;
lblProgText.Visible = true;
progressBar1.Visible = true;
lblProgress.Visible = true;
}
And then the code from the new class.
private void RunExcel()
{
string filepath;
filepath = txtboxSelectTxtFile.Text;
FileHelperEngine<ReadFile> engine = new FileHelperEngine<ReadFile>();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
ReadFile[] res = engine.ReadFile(filepath, 1);
ReadFile[] mes = engine.ReadFile(filepath);
int progrval = 0;
progrval = progressBar1.Value;
progressBar1.Minimum = 0;
progressBar1.Maximum = engine.TotalRecords;
Any idea what I should do? I have tried moving the code for the progressbar around and I get all sorts of errors on it.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You can't access controls from another threads. To manipulate them from other thread use Invoke method of ProgressBar class.
Giorgi Dalakishvili
#region signature
my articles
#endregion
modified on Tuesday, June 10, 2008 12:22 PM
|
|
|
|
|
|
Yes that is one of the possible solutions.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
I'm trying to make a splash screen with the following requirements:
1) Must fade in and fade out (issues)
2) Fades in before main program form is open and fades out once it is (done this)
3) Displays an image which is not squash and has transparency (issues)
So I've looked on the net and I'm still struggling with some aspects if anyone can assist. Fading the form is trivial (by setting the Opacity), however getting a form to be transparent (to work with the pictures transparency) and then fading that in and out is a mess.
I have tried numerous methods, such as overriding OnPaintBackground, changing the style of a form to allow a transparent background and a few other things. The problems I hit are:
- When fading the transparent form, by changing the Opacity the transparent bits turn black
- When the splash screen first shows it paints properly, but when the main form is finally loaded the transparent bits of the splash screen still show what was there before the form loaded (i.e. not repainting or something).
At the moment some of the code I have looks like this:
protected override void OnPaint(PaintEventArgs e)
{
}
protected override void OnPaintBackground(PaintEventArgs e)
{
Console.WriteLine("paintBackground");
Graphics gfx = e.Graphics;
gfx.DrawImage(global::DesktopLiveDotNet.Properties.Resources.splash_screen, new Rectangle(0, 0, Width, Height));
}
But when it starts to fade the transparency turns black:
private void timer1_Tick(object sender, EventArgs e)
{
Opacity = fOpacity / 100;
Application.DoEvents();
fOpacity -= StepVal;
if (fOpacity <= 0)
{
timer1.Stop();
Close();
}
}
Not quite sure how to proceed and any ideas would be great!
|
|
|
|
|
I have never been able to use BackGroundpainting successfully. Why not just paint normally?
|
|
|
|
|
I've tried that.
My problem is making the form's background disappear. I cannot get rid of the grey square (default form background color). So to do that I override the paintbackground method but that then draws black wherever the transparency is meant to be. Whether double buffered or not. It definitely draws black in the transparency when changing Opacity :/
|
|
|
|
|
i have stored procedure with two parameters as follows:
create procedure checkCompatability
(
@compatility varchar output,
@award_num int
)
AS
SET NOCOUNT OFF;
IF EXISTS (SELECT Award_num from table1 where award_num=@award_num)
begin
set @compatability='Y'
print @compatability
end
else
set @compatability='N'
print @compatability
GO
in C# parameters:
SqlCommand checkDone = new SqlCommand();
checkDone.Connection = con1;
checkDone.Connection.Open();
checkDone.CommandType = CommandType.StoredProcedure;
checkDone.CommandText = "checkCompatability";
SqlParameter comp = new SqlParameter("@compatability", SqlDbType.VarChar);
string S = comp.Value.ToString();\\null reference exception occours here
lblresult.Text = S.ToString();
comp.Direction = ParameterDirection.Output;
SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int);
complete.Direction = ParameterDirection.Input;
int awN = int.Parse(comboAwardNum.Text);
complete.Value =(int) awN;
lblresult.Text = comp.Value.ToString();
checkDone.Parameters.Add(comp);
checkDone.Parameters.Add(complete);
checkDone.ExecuteNonQuery();
checkDone.Connection.Close();
what is the problem with that code?
|
|
|
|
|
Mr.Kode wrote: what is the problem with that code?
I give up. What is the problem?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
|
Hi
I am trying to add Some code to ThisWorkbook in Excel file before opening it using C# but I can't.Can any body please tell me what to do?
the code looks like this:
Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
By the way I don't want to add this code in a standard module ,just in Thisworkbook.
thanks
[I am using VS 2008 and MS Office 2003]
my code looks like this but it adds to the Standard Module not ThisWorkBook:
Microsoft.Vbe.Interop.VBComponent oModule;
oModule = Excel_WorkBook.VBProject.VBComponents.Add(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule);
oModule.CodeModule.AddFromString("My Function Text");
|
|
|
|
|
Hi,
I'm storing data (not image) in my SQL database as a type varbinary.
Retrieving this table in a dataset.
With databinding i bind the datagrid to the dataset.
But the datagrid gives an error because it tries to convert byte[] to image (i guess.)
The columns are not persistent (predefined)
Anyone an idea how i can solve this ?
thx
kurt
|
|
|
|
|
Hi!
I am stuck in my approach.
I need to fetch files present in a folder with "day" and "year" (2, 2008) as parameter.
i need code for it. As of now i am able to fetch all the files present in the folder but am not able to fetch according to date. If anyone can help me, Thnx
|
|
|
|
|
Have a look at System.IO.File.GetCreationTime (or GetLastWriteTime), see if that will give you what you need.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
I would like to fetch the filename(with complete path) from windows explorer right menu?
please guide me.
|
|
|
|
|
|
Hi,
Not sure where the best place for this question would be, but hopefully someone might be able to help.
I have developed a .Net 2.0 windows service that utilises the MS Office Excel 12.0 PIA. I am looking into the implementation of this service onto a number of production web servers and ideally would like to not have to install the full version of Office 2007 onto each server. It is possible to download the Office 2007 PIA redistributable package, but Office 2007 must be installed as a prerequisite.
Is there anyway I can utilise the Office Interop's on a server that does not have Office installed?
Thanx, and apologise if this is posted in the wrong forum...
Clean code is the key to happiness.
|
|
|
|
|
The Office Primary Interop Assemblies do nothing by themselves. They simply provide a way to call the Office programs to do something on your program's behalf.
Even if they're not visible, the Office apps have to run when you call the methods in the PIAs. If you check Task Manager, you will see that (in this case) EXCEL.EXE is running.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Had a feeling that was the case.
Thanx for the quick response...
Clean code is the key to happiness.
|
|
|
|
|
Hi!
I have an application that has a keyboard-listener (system-hook).
It is being notified on any keyboad-event, even if the app-windows is not active.
As far as that it works as designed.
My problem is, that it is possible, that someone pushed the space-bar or the cursor-buttons, what effects on the GUI, e.g. to buttons, list-views, etc... So if someone presses the curser-buttons a highlight wanders around my gui. And if the spacebar is hit and a button was highlighted this button will be pressed. This is what i´d like to avoid.
What i´d like to have is to make the gui ignore these keyboard inputs (except textboxes, where you need the keyboard).
Is there a way of making the GUI-elements not react on keyboard-actions?
Thanx
J.
|
|
|
|
|
Dear All,
We have two (ASP.net) web applications running on Windows Server 2003. First application runs on Framework 2.0 and the second one runs on Framework 3.5.
Most of the client machines are having Vista and we are facing a strange problem, i.e. IE7 restarts very frequently. There is no error logged or displayed and the pattern is also not consistant. IE gets restarted at any page and next time it works well at the same page.
This problem occurs on Vista + IE7 environment only.
Please guide.
|
|
|
|
|
sachinkalse,
I dont think anyone is going to be able to help you as you are being too vague.
What is your app doing when it crashes? Have you stepped through your code to see if you are causing exceptions? Are you trying to access something that the user account doesn't have privileges for?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|