|
Thanks Steve!
You were right, I checked the whole project for DoWork and found that the Visual Studio had already added the DoWorkEventHandler in its generated code InitializeComponent()
Now after removing it, works as expected.
|
|
|
|
|
I would like to upload file one by one using BackgroundWorker. But it seems the application using multi-thread to uplaod. Is there any methods like Thread.join on backgroundWorker?
Thanks,
Mimi
|
|
|
|
|
Do you want to wait till background worker finishes? Use waithandles. Call WaitOne() when process starts. Handle RunWorkerCompleted event and signal your waithandle.
|
|
|
|
|
can you show me the example how waithandles work with BackgroundWorker.
Thanks.
|
|
|
|
|
Implementing waithandles is trivial. Here is a console application.
class Program{
static EventWaitHandle handle = new AutoResetEvent(false);
static void Main(string[] args) {
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
Console.WriteLine("Main thread waiting");
handle.WaitOne();
Console.WriteLine("Main thread released.");
Console.Read();
}
static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
Console.WriteLine("Worker finished. Releasing main thread");
handle.Set();
}
static void worker_DoWork(object sender, DoWorkEventArgs e) {
Thread.Sleep(1000);
}
} Hope it is clear now
|
|
|
|
|
That's because a BackgroundWorker is a thread. If you want to use a thread to upload a file (presumably to keep the UI responsive during the upload), a join is pointless.
Set your backgroundworker to report its progress, add the appropriate event handler, and add a control that's updated when the backgroundworker reports its progress.
If you want the program to not allow input during the upload, don't use a thread (or async upload).
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
How do i compress and decompress an image using GDI+ JPEG methods?
|
|
|
|
|
You don't really 'compress' when you save as a jpeg. You are throwing out alot of data.
There is no way to uncompress a jpeg image. You can save it as a bitmap and its size will increase dramatically, but it will still have all the artifacts from the jpeg. If you want to 'compress' an image and keep the original quality, save it as a PNG or something.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I have a C# Windows form with a button on it. When the button click event occurs I open a new mail message and supply the mail reciepients and subject. When the user clicks the send button I want to retrieve the mail body for my app.
Is there a way to do this using the application.itemsend event? If so is there any sample code out there showing this.
Thanks!
|
|
|
|
|
hi is there any another method that API to loading FIB(header of Doc. file) i founde i must access to root storage so will access to FIB
i want to hiding data in unued sector
|
|
|
|
|
I want to install a plugin that will recognize specific text in a web page and let me rewrite the output for that word as a link or as bold or something to that effect. This is obviously very simple. What is the best way to do it?
|
|
|
|
|
Hi,
I'm new to Crystal Reports and this is the first report I have written. Heres the problem: I've generated a report viewer that automatically logs in to the SQL server to pull the data. This part works fine and shows the report. I have also created two date pickers for the user to select a date range and refresh the report. When the user clicks the generate button, a Crystal Database login window prompt opens. All the information is already filled in except the password.
How can I make it so this refreshed report also automatically logs in.
<br />
namespace Val_Report<br />
{<br />
public partial class Form1 : Form<br />
{<br />
<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
ConfigureCrystalReports();<br />
<br />
<br />
DateTime firstDay = DateTime.Now;<br />
DateTime FirstDayInMonth = new DateTime(firstDay.Year, firstDay.Month, 1);<br />
string strStartDate = FirstDayInMonth.ToShortDateString();<br />
orderStartDate.Value = FirstDayInMonth;<br />
<br />
string strEndDate = DateTime.Now.ToShortDateString();<br />
<br />
orderEndDate.Value = DateTime.Now;<br />
<br />
setReportParameters(strStartDate, strEndDate);<br />
}<br />
<br />
private void ConfigureCrystalReports()<br />
{<br />
ConnectionInfo connectionInfo = new ConnectionInfo();<br />
connectionInfo.ServerName = "xxx";<br />
connectionInfo.DatabaseName = "xxx";<br />
connectionInfo.UserID = "xxx";<br />
connectionInfo.Password = "xxx";<br />
<br />
string reportPath = Application.StartupPath + "\\" + "CrystalReport1.rpt";<br />
crystalReportViewer.ReportSource = reportPath;<br />
<br />
SetDBLogonForReport(connectionInfo);<br />
<br />
}<br />
<br />
private void SetDBLogonForReport(ConnectionInfo connectionInfo)<br />
{<br />
TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;<br />
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)<br />
{<br />
tableLogOnInfo.ConnectionInfo = connectionInfo;<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
private void crystalReportViewer_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
<br />
private void setReportParameters(string strStartDate, string strEndDate)<br />
{<br />
<br />
ParameterFields paramFields = new ParameterFields();<br />
<br />
ParameterField pfStartDate = new ParameterField();<br />
ParameterField pfEndDate = new ParameterField();<br />
<br />
<br />
pfStartDate.ParameterFieldName = "StartDate";<br />
pfEndDate.ParameterFieldName = "EndDate";<br />
<br />
ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();<br />
ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();<br />
<br />
<br />
dcStartDate.Value = DateTime.Parse(strStartDate);<br />
dcEndDate.Value = DateTime.Parse(strEndDate);<br />
<br />
<br />
pfStartDate.CurrentValues.Add(dcStartDate);<br />
pfEndDate.CurrentValues.Add(dcEndDate);<br />
<br />
<br />
paramFields.Add(pfStartDate);<br />
paramFields.Add(pfEndDate);<br />
<br />
<br />
crystalReportViewer.ParameterFieldInfo = paramFields;<br />
}<br />
<br />
private void redisplay_Click_1(object sender, EventArgs e)<br />
{<br />
<br />
<br />
string strStartDate = orderStartDate.Text;<br />
string strEndDate = orderEndDate.Text;<br />
<br />
string reportPath = Application.StartupPath + "\\" + "CrystalReport1.rpt";<br />
crystalReportViewer.ReportSource = reportPath;<br />
<br />
setReportParameters(strStartDate, strEndDate);<br />
}<br />
<br />
|
|
|
|
|
Hi,
i would like to export my db (*.mdf) and i have choosen the simplest (i think) way. Just copy the file. The problem is, that i already use this file, so i can't open it. I don't open it at first place, sqlservr.exe does and so i have no control about it.
I searched these forums, but i have found only this
FileStream fs = new FileStream(getDbPath(), FileMode.Open, FileAccess.Read, FileShare.Read))
And in my case it doesn't work.
|
|
|
|
|
If you copy the database files that is in use, you don't know if they are complete. The database driver may be in the middle of changing something in the files, so in that case your copy would be corrupted.
If you close all connections to the database, the driver should release the files. The problem with that is that there is a connection pool in .NET that may keep connections, so you would either have to quit your application or manipulate the connection pool.
If you detach the database, it's safe to copy the files.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
thanks so much for your answer. I googled for detaching the db. Unfortunately sp_detach_db says, that the db is currently in use.
My usage:
SqlConnection conn = daAuthors.Connection;
if (daAuthors != null)
{
daAuthors.Connection.Close();
daAuthors.Dispose();
daAuthors = null;
}
SqlCommand cmd = new SqlCommand(string.Format("sp_detach_db @dbname='{0}'", conn.Database), conn);
cmd.ExecuteNonQuery();
Then i read about ALTER DATABASE DatabaseName SET SINGLE_USER; to obtain exclusive access to db. But i don't know the database name, the "sysname". I have created the db in VS. For sp_detach_db it is path to *.mdf. When i run sp_helpdb , it shows me all db names, but they are just paths to dbs.
|
|
|
|
|
Hi;
I'm a C#.net newbee trying to convert from VB.net. Don't have the big picture yet I am sure.
I am trying to trap the mouse_move event in a panel (container) for the form the code (that works) looks something like this.
InitializeComponent();
this.MouseMove += new MouseEventHandler(this.Form1_MouseMove);
}
//--------------------- Mouse Move ------------------------------
//
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
......
}
If I try to do the same thing in a container it does not work.
Can anyone point me in the right direction.....
Thanks In Advance
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
modified on Friday, September 19, 2008 12:02 AM
|
|
|
|
|
You want to trap mouse move over a panel control, however the event which you have added is for mouse move event of Form and not of panel control.
Therefore add event handler for panel control, such as –
-----------------------------
private void Form1_Load(object sender, EventArgs e)
{
this.panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
}
void panel1_MouseMove(object sender, MouseEventArgs e)
{
//Mouse move event of panel
}
--------------------
-Dave.
------------------------------------
http://www.componentone.com
------------------------------------
|
|
|
|
|
thx dave;
the code I supplied was the code that works for the form mouse move event. The code that I am trying to get working is...
private void Form1_Load(object sender, EventArgs e)
{
this.MouseMove += new MouseEventHandler(this.panel1_MouseMove);
}
//--------------------- Mouse Move ------------------------------
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
Point mousePoint = PointToClient(MousePosition);
string msg = string.Format("X:{0}, Y:{1}",
mousePoint.X,
mousePoint.Y);
lblMousePosition.Text = msg;
}
thx
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
I think you are still not getting the point.
If this is the code which you have used –
private void Form1_Load(object sender, EventArgs e)
{
this.MouseMove += new MouseEventHandler(this.panel1_MouseMove);
}
//--------------------- Mouse Move ------------------------------
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
Point mousePoint = PointToClient(MousePosition);
string msg = string.Format("X:{0}, Y:{1}",
mousePoint.X,
mousePoint.Y);
lblMousePosition.Text = msg;
}
Notice that you are using line –
this.MouseMove += new MouseEventHandler(this.panel1_MouseMove);
In the above line ‘this’ represents form, and not a panel. So still you are not getting a handler for panel control.
Replace the above mentioned line with –
panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
Notice that I am using ‘panel1.MouseMove’ and not ‘this.MouseMove’. Here panel1 is name of my panel control, if you have used a different name, you should replace it with the name of your panel control.
-Dave.
------------------------------------
http://www.componentone.com
------------------------------------
|
|
|
|
|
Thanks again Dave;
I think that I have found the problem this event does not fire. Not sure why but the Form Load nevers fires therefore mouse move is not working
...
private void Form1_Load(object sender, EventArgs e)
but it does not...
THX
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
So in order to get the Form Load event to work I added this to the Designer of the form
this.Load += new System.EventHandler(this.Form1_Load);
do I need to do this or should VS add this for me when I add the event??
Sorry for these "bone-head" questions but this is the kind-of stuff VB would have added automatically and I'm not sure what has to be added when.
THX
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Can I restrict a template parameter to primitive (or unmanaged) types only? Is it possible to enforce this condition so that I can take a pointer to it?
class Example<t> where T : struct {
T* p;
}</t>
I get an error because T is a managed type. I understand this, but is there a way to tell the compiler that it's a native type (e.g. int or double )?
|
|
|
|
|
|
|
DataTable dt = new DataTable("SomeTable");
string[] tokens;
dt.Columns.Add("ID",typeof(int));
dt.Columns.Add("Name",typeof(string));
StreamReader sr = new StreamReader("C:\\SomeFile.csv");
while (!sr.EndOfStream)
{
tokens = sr.ReadLine().Split(',');
if (tokens.Length == 2)
dt.Rows.Add(tokens);
string strExpression = "ID = 1";
DataRow[] dr = dt.Select(strExpression);
MessageBox.Show(dr[0].ToString());
Can you tell me how would you build and use a select expression and use it in DataTable.Select()
Please, dont link me to some website, but give me your experience or at least try it and let me know how it works.
Many thanks guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|