|
Hey got it. Solved the problem by setting the control's selected item index to the corresponding text that I set for the control.
Vijay
|
|
|
|
|
Hi,
after reading a lot of forum threads i am wondering that no one else has the problem I am having. Here it is: I am starting programming with C# and .NET with VisualC# Express. I tried to implement multithreading in my test app. The app runs but when I set breakpoint in the code that is executed by a worker thread then:
- the debugger stops at the breakpoint
- the GUI freezes for a couple of seconds and then
- I am not able to get the interrupted thread running again
I have written a small test application to demonstrate this behaviour. It opens a form with a button and 4 textboxes. When the button is pressed 4 threads will be started, that increment a local variable and display the value of the variable in the textbox (each thread has its own textbox). When the threads are running I can see that the numbers in the textboxes are increasing. When I set a breakpoint in the thread code, the execution stops. I must wait a few seconds before the GUI (VC) responds and if I then let the app run again (after removing the breakpoint) I can see that the thread that was interrupted does not work anymore (textbox value does not change).
What could cause this behaviour. I think that I am having a general problem but I dont know where to start to search.
The source of the test application:
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 MTWindowsTestApp
{
public partial class Form1 : Form
{
int m_nThreadCount;
bool m_bExit;
public Form1()
{
InitializeComponent();
m_nThreadCount = 0;
m_bExit = false;
}
private void button1_Click( object sender, EventArgs e )
{
Thread t;
int i;
for( i = 0; i < 4; ++i )
{
t = new Thread( new ParameterizedThreadStart( MyThread ) );
t.Priority = ThreadPriority.BelowNormal;
t.Start( new ThreadData( m_nThreadCount++ ) );
}
}
public delegate void SetTextDelegate( string strText,
ThreadData td );
public void SetText( string strText, ThreadData td )
{
switch( td.m_nNr )
{
case 0:
{
textBox1.Text = strText;
break;
}
case 1:
{
textBox2.Text = strText;
break;
}
case 2:
{
textBox3.Text = strText;
break;
}
case 3:
{
textBox4.Text = strText;
break;
}
}
}
public void MyThread( object Data )
{
int nCount;
int nData = ( (ThreadData)Data ).m_nNr;
string strTemp;
nCount = 0;
strTemp = nData.ToString();
while( true )
{
strTemp = "Thread " + nData.ToString() + ": " +
nCount.ToString();
BeginInvoke( new SetTextDelegate( SetText ),
new object[] { strTemp, Data } );
nCount++;
Thread.Sleep( 10 );
}
}
private void Form1_FormClosing( object sender, FormClosingEventArgs e )
{
m_bExit = true;
}
}
public class ThreadData
{
public int m_nNr;
public ThreadData( int nNr )
{
m_nNr = nNr;
}
}
}
Thanks in advance.
|
|
|
|
|
Hmph... I can't reporoduce your error... everything works fine, and your code looks solid.
Only thing that I added is t.IsBackground = true; when you declare thread or else application crashes when you close it in middle of work... try with that line.
|
|
|
|
|
Adding that line makes no difference. To be more clearly, the code works on my machine too. But I am not able to stop the worker thread with a breakpoint. If I do, it wont ever run again.
|
|
|
|
|
I have noticed furthermore the following: The first thread that gets halted by the debugger does not respond anymore. The remaining threads can be halted and executed stepwise. No problem. It is only the first time a thread gets halted, that this thread does not work anymore. As there seems to be no one with that problem (besides me), I assume that there must be a problem with the configuration of my machine.
I have two machines with VC#8 and both have this behaviour. On both machines is installed:
- Windows XP SP2
- VisualC++ 6 Enterprise
- VisualC# Express
- WindowsXP SP2 SDK
Do I have to be member of a special group (Windows User Group) for the debugger to work correctly?
Anyone any other idea???
|
|
|
|
|
Hi,
I have found the reason for this behaviour (although I think that it is a bug). The problem is the "Locals" window in the debugger. It shows the local variables of the current context and "this". And this is the problem. If I switch to the window "Überwachung" (maybe "Watch" in english?), the problem is not there. If I put "this" in the watch window, the problem is there again.
Summary: If we set a breakpoint in our application inside thread code and the "local" window is open when the thread reaches the breakpoint so that execution stops, the halted thread is dead from now on.
I am still wondering that no one else had this problem...
|
|
|
|
|
I created a table that the first column is "ID",Fname,Lname.
the "ID" is set to be primary.
when i am doing the insert command: "insert into table (Fname,Lname) values (y,t)"
i get and error that says that ID can not get NULL, i thought that it should be increased automatically.
the error:
Cannot insert the value NULL into column 'ID', table 'RTQ.dbo.Users'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I do not want there NULL, i created it "int" so it could put nubers there.
what am i doing wrong???
Thanks
|
|
|
|
|
First this is the C# board and not the SQL board. Posting on the right board will get you answers faster.
What you need to do is have the ID field set up as an identity field so that it will increment automatically.
Steve Maier, MCSD MCAD
|
|
|
|
|
hi guys,
I have a picBox and a list of pictures. These pictures are displayed in ordered by 2 button ( previous and next ) in the picBox. When clicking buttonDelete, I want to delete the picture which is being displayed in picBox at present and then,another pic is displayed in picBox. But,if any pictures were displayed in the past, it couldn't be deleted. (error: ... because it is being used by another process.)
F1 - help me . thanks !!!
-- modified at 13:53 Monday 27th February, 2006
|
|
|
|
|
Hi!
How are you trying to delete the image displayed in the PictureBox ? To get an empty PictureBox you can simply assign null to the Image property.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
I only want to delete the picture displaying on PictureBox,and then the pictureBox will display next( or previous) picture in my list Picture.
-- modified at 21:26 Monday 27th February, 2006
|
|
|
|
|
Still not sure what you really want.
Are you trying to delete the file the picture has been loaded from or something else? Please be more clear.
And if you try something already and "it does not work", then the exact error message you get is essential for us to help you.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
yes, i'm trying to delete the picture file has been loaded into PictureBox.
I think the picture that has been loaded into PictureBox is saved into a "temp" memory or something else,isn't it?
|
|
|
|
|
Ok, now that we know what your problem is, we can help you...
You have to make sure the image file isn't being used any more.
The most probable cause is that the image that has been assigned to the PictureBox hasn't been disposed of yet.
First, you'll have to make sure you don't let any old references hanging around when you load an image into your PictureBox. For example, when setting an image to display you could write
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
pictureBox1.Image = newImageToShow; That way, only the image currently shown in the PictureBox is used.
Before you can delete the file, you'll also have to remove any references, for example:
private void buttonDelete_Pressed(object sender, EventArgs e)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
File.Delete(pathToCurrentImage);
}
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
oh, pictureBox1.Image.Dispose(); thanks !
Then,can i ask you about form size?
I have an user control added into a form. I used the following code in both Form_load() and Form_SizeChanged but the usc size wasn't changed:
uscImage_NEW.UserControl1 usc=new uscImage_NEW.UserControl1();
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
usc.Left=0;
usc.Top=0;
usc.Width=this.Width;
usc.Height=this.Height;
}
how to solve this problem?
|
|
|
|
|
Why don't you just anchor or dock the UC?
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
I did with another objects such as one button, one lable or anything else in another project... its size was changed. In usc project, i tried but the usc size was unchanged.
|
|
|
|
|
Hi
After deploying ASP.net 1.1 application, when a user hits a page first time, it takes lot of time to load because MSIL code needs to be translated to native format. But, if we have several pages in application, it can give bad impression that the site is slow.
Is there a way after deploying, I can automatically turn all the pages from MSIL to native format for fast loading?
Please advice.
Thanks
Pankaj
|
|
|
|
|
Hi!
You'd want to start reading on a tool called ngen (part of the framework sdk).
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
pankazmittal wrote: it takes lot of time to load because MSIL code needs to be translated to native format.
Sorry, that is not correct. ASP.NET takes time to compile the aspx ascx pages into C# assemblies. You can make this load faster by moving most of your code to the code-behind class.
|
|
|
|
|
|
Hi, Im developing a console application in visual studio and I just want my project to produce a .exe like in C. Is this possible? I can run it from the start..debugging thing but I want the exe. Also how do you run from VS and pass in command Arguements? Thanks in advance
|
|
|
|
|
For VS 2005, for existing application, in solution explorer, right click on the project and choose "Properties", you will see Properties Tabs Windows. Select "Application" Tab and there is a combobox called "Output Type", select "Console Application", you will get Console Application like C.(for new apps, choose Console Application in start up.) For Command Line Arguments, don't close properties tabs windows. Select "Debug". You will see "Start Options", there you can set "Command Line Arguments" and "Working directory" as well.
For VS 2003, in solution explorer, right click on the project and choose "Properties", you will see Property Pages Dialog. On left window, you will see "common Properties" and "Configuration Properties". Expand "Configiration Properties", you will see "Debugging". On the right side, you will see "Start Options", expand this. You see "Command Line Arguments" and "Working Directory".
Enjoy!
|
|
|
|
|
The .exe is in your projects 'bin\Debug' folder.
Wacky waving inflateable arm flailing tube man!
- Family Guy
|
|
|
|
|
hi guys,
in my client/server application, i have a list in my server of connected clients. if the physical connection of the network is dropped, i would like to start a timer in the server app that will count up to lets say 2 minutes and by that time if the client still did not respond i would like to remove that client from the list. how will i create multiple timers to monitor each of my clients?
or if you can suggest a better way of doing this, i accept suggestions. thnx
|
|
|
|