|
<br />
int i;<br />
Form2 f2=new Form2();<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
f2.Show();<br />
f2.textBox1.Text=i.ToString();<br />
loop();<br />
}<br />
private void loop()<br />
{<br />
for(i=1; i<1000000;i++)<br />
{<br />
f2.textBox1.Text=i.ToString();<br />
f2.Refresh();<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
With above code, I want to let i show in the testbox1 of form2 while the interation in funcion loop in going on. When I run the program. at first it works, but after i get to around 10000, the form2 freezs,and it will not update the value of i. If I click the form. The form2 's text will show some thing like ( not responding).
How can I fix this problem?
Thank.
|
|
|
|
|
Threads would solve your problems. Create the second form on a separate thread (and paint it - set the text property to aother controls) and all things should run smoothly.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Thank you for your response.
I have never program in thread. can you please give me an example or a source online where i can find an example?
Thanks
|
|
|
|
|
Search on CodeProject an example of SplashScreen (they are kind o the same, use threads in order to display dinmicaly changing data)
Implementing with threads your solution may not be the best method, but from what I can imagine this may work fine. If you want me to help you more specify in what circumstances you show the second form, and how long (until a button is pressed, or until a time is elapsed)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Here's some code. No comments, though. I'm sick today and don't feel that loquacious. Hope it helps.
using System;
using System.Threading;
using System.Windows.Forms;
namespace Project1
{
public class MainForm : Form
{
private OtherForm otherForm;
public MainForm()
{
otherForm = new OtherForm();
Button b = new Button();
b.Text = "Click Me";
b.Click += new EventHandler( RunAThread );
Controls.Add( b );
}
private void RunAThread( object sender, EventArgs ea )
{
otherForm.Show();
ThreadWorker tw = new ThreadWorker( otherForm.tb, new OtherForm.UpdateText( otherForm.UpdateTextBoxText ) );
Thread t = new Thread( new ThreadStart( tw.RunAlotOfIterations ) );
t.IsBackground = true;
t.Start();
}
[STAThread]
public static void Main( string[] args )
{
Application.Run( new MainForm() );
}
}
public class OtherForm : Form
{
public TextBox tb;
public OtherForm()
{
tb = new TextBox();
tb.Dock = DockStyle.Fill;
Controls.Add( tb );
}
public delegate void UpdateText( string text );
public void UpdateTextBoxText( string text )
{
Controls[ 0 ].Text = text;
}
}
public class ThreadWorker
{
private Control c;
private OtherForm.UpdateText ut;
public ThreadWorker( Control target, OtherForm.UpdateText del )
{
c = target;
ut = del;
}
public void RunAlotOfIterations()
{
for( int i = 1; i < 1000000; i++ )
{
c.Invoke( ut, new object[] { i.ToString() } );
}
}
}
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
In this case, launching another thread is overkill. All you need to do is let your app process the WM_PAINT messages it's getting when you call .Refresh()
private void loop()
{
for(i=1; i<1000000;i++)
{
f2.textBox1.Text=i.ToString();
f2.Refresh();
Application.DoEvents();
}
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a data grid that is displaying data from a MSAccess Database. Using a oleDbAdapter. Everything works well with the datagrid, add/update/insert/delete, are all good when I type directly into a cell. Howevere, when I choose a value from a combo box, outside the datagrid, and press a button that changes a selected cell in the datagrid, the update to the database does not occur. I know it has something to do with typing directly into the cell versus just setting the cell equal to a value.
//This line of code successfully puts the data in the grid
dataGrid1[gRowSelected,4] = cmbGenre.Text;
//But the update of the DB does not happen, A restart of the app shows the previous data
oleDbDataAdapter1.Update(myDataSet);
myDataSet.AcceptChanges();
dataGrid1.Update();
does anyone know how I can get the data I put into the grid to get into the Database? Do I need to refresh that dataset from the datagrid? Is that possible? Any clues????
Thanks
AuZi2005
|
|
|
|
|
I think that you should get the row you are trying to modify and do your stuff there (if you want the row selected in the grid use the grid's BindingManager, or if you know some field from the row use the DataTable's Select method, ...)
Hope this helps.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Thanks, the reference to the Grid's BindingManager was what I was looking for. Did not know how to use the grid to get back to the dataset. got it working, thanks
|
|
|
|
|
Hello,
I hope someone can help with this problem.
I'm working on an app which reads the company database for a range of scanned images according to user and date. It retrieves a list of all relevant scans and displays the results in a datagrid, date scanned, image location etc. The image is not displayed.
When I hit the Export button, the 'grid is made into an Excel spreadsheet and all the images downloaded locally. I need the image location column of the spreadsheet to be a relative hyperlink to the local copy of the images that were downloaded.
I can go into the spreadsheet and manually turn every link into a hyperlink which is OK when the result set is only a few lines but there could be hundreds of rows potentially. I want to be able to do it programatically. Any ideas?
I've messed about with the text in the spreadsheet as it is written with things like
xl.Cells[rowIndex + 1, 5] = "/images/" + filename.Substring(45, 10) + ".jpg";
trying to turn it into a relative link this way but no dice.
Any ideas please, as I'm stumped.
Thanks in advance and Merry Christmas to everyone
Scott
scotlandc
|
|
|
|
|
I need to have a menu with similar look and feel like the MainMenu except that I need to be able to put it anywhere in form( making little flexible). I started having Panel as holding main menu items. I need to provide functionality pretty much same as MainMenu. That means if a menu item has children it should be able to add an arrow to the right and show the sub menus on mouse over and make appropriate menus invisible on mouse out.
I would appreciate if anyone would throw some light into it.
Thanks in advance,
VPMahank
|
|
|
|
|
i need to create a table with this value for every row:
Text
Text
Hyperlink
Note
Text
i've to thounght about create an excel table in my form.
My question are:
1)How can i control the field so to create hyperlink, set value or delete?
2)I've serched on COM dll about excel but i've found nothing!
Where is the excel dll?
|
|
|
|
|
Check out the Microsoft PIA's.
|
|
|
|
|
Hi,
Could you please recommend one good book on .net 2.0 and sql server 2005 (win or web)
Thanks
|
|
|
|
|
Hi,
I have written a software (a windows application) in C#.NET that is used by many clients of our company. Now my supervisor wants me to implement an auto update feature for the application. I think i am looking at a situation where my application needs to call a webservice to know if a newer version exists and if it does, it needs to download and execute the new version. Am I thinking in the right direction? If yes, can anyone provide me with what i need to do exactly? Any ideas will be highly appreciated.
Thanks,
Sandeep.
|
|
|
|
|
|
i had to do something similar at my company...small company here's what i did.
we have a networked server that everyone inhouse can access. the version number is located in the assembly of the app and i compare that to a data file located on the server (you can use streamreader to do that, or if you have a database back end that you can have the version information located inside of some table that you can query off of). you will need to make a deployment application (plenty of literature out there on that).
here's what i did:
-create deployment app (one of the projects that you can put in your solution) and compile: (.msi file is created)
-put msi file in shared server directory and resolve the directory path to some web address
-when the person logs into the app (im assuming through some login screen), a query is run to check the assembly version of the one on their computer as opposed to the most updated version
-if they require an update, this is what you do:
-implement the System.Net.WebClient class and download the msi off the server via the web address
-use the DownloadFile method of the webclient class
-save to a local directory (c:\temp perhaps...or somethign along those lines)
-execute the msi process using: System.Diagnostics.Process.Start("c:\TEMP\yourapp.msi")
-and then close your application: this.close() or something along those lines
-the installation should run as normal and then the user can start up the application again
-obvioulsy the version will be correct and this process wont happen again.
-read up on deployment applications, im sure you can do something manual like copy each executable manually over the web, but the msi makes it much easier...creats short cuts and everything.
only bad thing is that you're going to have to manually install the first version of this on each person's computer
best of luck
|
|
|
|
|
Thank you very much for the tip. I was wondering how i could download files from a web address and you just solved my problem.
Cheers!
|
|
|
|
|
I'm getting a "Failed to open database using..." error when attempting to connect to SQL Server located on a remote machine, using a user account login. Do I need to use a different Account setting? I'm currently using ServiceAccount.LocalSystem.
(and yes, I posted this in the ADO.NET forum too, but forgive me, this forum gets a lot more traffic).
Marc
VS2005 Tips & Tricks -- contributions welcome!
|
|
|
|
|
I guess you are using a windows service to connect to the database. The settting you have seems to be fine. Make sure the connection string you use has the username and password of an account that has accesss to your database. That should solve your issue.
|
|
|
|
|
You need to be running the service with a different account. LocalSystem is allowed access only to local resources. Sometimes even accessing localhost via TCP/IP will not work with this account!
Go to the Control Panel/Administrative Tools/Services, double-click the service and under the Logon tab, change the account to one that is allowed to access the DB (or even just a domain account or even a local account on the server if you're not using Windows authentication to connect to the DB).
--
Umm... what's a .sig? ;]
|
|
|
|
|
How can I access HttpApplication object within the class which does not belong to the same namespace as the application?
Thank you.
talbot
|
|
|
|
|
Use the full name of the class. MyNamespace.Classname
|
|
|
|
|
I don't want access the class, but the current instance of the application. How can I obtain the reference to the app?
|
|
|
|
|
Pass the instance of the application as an object in the constructor for your class.
|
|
|
|