|
Here is most of your problem:
private void Form1_Load(object sender, EventArgs e)
{
for (cnt1 = 0; cnt1 <= tot1; cnt1++)
{
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
bgw.WorkerReportsProgress = true;
if (!bgw.IsBusy)
{
bgw.RunWorkerAsync();
}
}
} Each time round the loop, you construct a new worker, and kick it off to do the task. But...you only specify the one handler for all the workers, and you don't check in the handler method which worker you are processing for. And since you always write a value to the same label, you always get the one value from the last worker to execute.
Add that the worker doesn't do anything that takes much time, and only reports a single value, and it all looks a bit dodgy!
I've tidied it up a bit and made it so it should work:
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
for (int i = 0; i <= 100; i++)
{
System.Threading.Thread.Sleep(500);
worker.ReportProgress(i);
}
}
void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
label1.Text = String.Format("Progress: {0} %", e.ProgressPercentage);
}
void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
BackgroundWorker bgw = new BackgroundWorker();
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
bgw.WorkerReportsProgress = true;
bgw.RunWorkerAsync();
}
The only instant messaging I do involves my middle finger.
English doesn't borrow from other languages.
English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.
|
|
|
|
|
the problem is
i run my application-->selected one radio button -->then closed m application.
if i run my application next time ,that form should be opened by selecting the previous radio button. i need to store those values in app.config .how to store them dynamically in app.config
other than app.config plz give solution
|
|
|
|
|
You can update the App.Config during runtime[^]. Please remember that this may not work if your app.config is located in a read-only location, I'd therefore recommend you to use a second configuration file located in a writable location, e.g. the AppConfig folder to avoid crashes and malfunction of your program after it was not able to modify the app.config because it may read-only.
|
|
|
|
|
|
For using the settings.settings check out this MSDN Page[^]
Everything you need to know you should be able to find there
Probably you forgot to call the "Save" method after changing the value of the setting.
|
|
|
|
|
thanq. i forgot to call save().
|
|
|
|
|
for (int num = 0; num < treeList1.ViewInfo.RowsInfo.Rows.Count; num++)
{
}
All people for me query as a way that get the value of each line in TreeList, thanks.
|
|
|
|
|
Iterate the nodes; there's documentation here[^], and DevExpress has their own forum, specializing in their own products.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What the use of this code:
foreach (TerminalGroup tg in vps) return tg;
Is there a benefit using this over something like:
if (vps.Length > 0) return vps[0]
I see this used more often, it's seems to be done deliberately.
|
|
|
|
|
I would suggest that the first version is lazy coding.
|
|
|
|
|
The first one also works when the collection is enumerable but has no indexer (though I don't really like that code even in that situation). Apart from that, AFAIK there's no point.
|
|
|
|
|
It's not some strange code trick that is a millisecond faster because it does less checks or so?
|
|
|
|
|
Depends on what the thing is.
For arrays, there is literally no difference. The assembly code generated by the JIT compiler is exactly the same, at least in my test case.
static int Test2(int[] array)
{
if (array.Length > 0)
return array[0];
throw new Exception();
}
static int Test1(int[] array)
{
foreach (int i in array)
return i;
throw new Exception();
}
push rbx
sub rsp,20h
mov rax,qword ptr [rcx+8]
test eax,eax
jle 0000000000000020
test rax,rax
jbe 0000000000000040
mov eax,dword ptr [rcx+10h]
add rsp,20h
pop rbx
ret
For other things, of course you can construct a type such that indexing is slow (always, also at index 0) and enumeration is fast, but usually starting to enumerate means setting up a little state machine (takes some non-zero but usually tiny amount of time) and indexing at index 0 is usually trivial.
TL;DR I would guesstimate that the second way is faster more often than it is slower.
|
|
|
|
|
Hello,
In my program I need to be checked if the database was deleted, the program creates it again. So, I made a database and connected it to my program with 'LINQ-To-SQL-Classes', when I delete the database manually ("Database1.mdf" and "Database1_log.ldf"), it cannot create the database and show me this error:
" Database 'C:\Users\Saleh\documents\visual studio 2010\Projects\St\St\bin\Debug\Database1.mdf' already exists. Choose a different database name. "
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
string strDBPath = Application.StartupPath + ("\\Database1.mdf");
DataClasses1DataContext objDB = new DataClasses1DataContext(strDBPath);
if (!objDB.DatabaseExists())
{
objDB.CreateDatabase();
MessageBox.Show("Database created!");
}
}
How can I handle it?
Thanks in advance!
|
|
|
|
|
am placing interval value in app.config as
<add key="TCPIP" value="192.168.2.130"/>
<add key="tcpport" value="6000"/>
<add key="tcpadderss" value="FF"/>
<add key="comaddress" value="FF"/>
<add key="interval" value="200"/>
then now i want to assign that value to combobox in c#
textBox8.Text = System.Configuration.ConfigurationManager.AppSettings["TCPIP"];
textBox7.Text = System.Configuration.ConfigurationManager.AppSettings["tcpport"];
textBox9.Text = System.Configuration.ConfigurationManager.AppSettings["tcpadderss"];
Edit_CmdComAddr.Text = System.Configuration.ConfigurationManager.AppSettings["comaddress"];
comboBox1.SelectedItem= System.Configuration.ConfigurationManager.AppSettings["interval"];
in case of textboxes it's working fine. but how to assign interval value to combox.when i run the project form shoul load with that interval value
|
|
|
|
|
If for your combobox value and text both are same then you may use comboBox1.SelectedValue .
Regards,
CodeBlack
|
|
|
|
|
thanq i got it. but now the problem is
i run my application-->selected one radio button -->then closed m application.
if i run my application next time ,that form should be opened by selecting the previous radio button. i need to store those values in app.config .how to store them dynamically in app.config
-- modified 8-Nov-13 5:10am.
|
|
|
|
|
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["test"].Value = "blah";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
It was worked for me.
Don't forget to mark it as an answer.
Regards,
CodeBlack
|
|
|
|
|
sorry it's not working for me.how can i test ,whether it's working or not.
i kept that code in radiobutton_checkedChanged().and changed test-->tcpradio and blah-->true
in app.config
<appSettings>
<add key="tcpradio" value="0"/>
</appSettings>
plz help me
|
|
|
|
|
is it your windows application ?
Regards,
CodeBlack
|
|
|
|
|
yes it's windows application.vs2010 c# 4.0
|
|
|
|
|
Agreed on what Bernhard Hiller said. There are many options to achieve the same thing.
For example,
you can create a cookie and set value into cookie and define cookie expiration time Or
you can use the application data (AppData)folder. or
you can store it in database as well.
Store it in app.config only if there is no any other way.
Regards,
CodeBlack
|
|
|
|
|
If you want to change the values from your program, use settings - app.config is not the correct place for that.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OtherLibs;
using CxCore;
namespace oneMoreTry
{
public partial class Form1 : Form
{
private CvCapture VideoCapture;
private IplImage frame;
private IplImage imgMain;
bool capture = false;
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
capture = true;
}
private void btnVideo_Click(object sender, EventArgs e)
{
double vidWidth, vidHeight;
VideoCapture = highgui.CvCreateCameraCapture(0);
if (btnVideo.Text.CompareTo("Start Video") == 0)
{
if (VideoCapture.ptr == IntPtr.Zero)
{
MessageBox.Show("badtrip ah!!!");
return;
}
btnVideo.Text = "Stop Video";
highgui.CvSetCaptureProperty(ref VideoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
highgui.CvSetCaptureProperty(ref VideoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 480);
highgui.CvQueryFrame(ref VideoCapture);
vidWidth = highgui.cvGetCaptureProperty(VideoCapture, highgui.CV_CAP_PROP_FRAME_WIDTH);
vidHeight = highgui.cvGetCaptureProperty(VideoCapture, highgui.CV_CAP_PROP_FRAME_HEIGHT);
picBoxMain.Width = (int)vidWidth;
picBoxMain.Height = (int)vidHeight;
timerGrab.Interval = 42;
timerGrab.Enabled = true;
}
else
{
btnVideo.Text = "Start Video";
timerGrab.Enabled = false;
if (VideoCapture.ptr == IntPtr.Zero)
{
highgui.CvReleaseCapture(ref VideoCapture);
VideoCapture.ptr = IntPtr.Zero;
}
}
}
private void timerGrab_Tick(object sender, EventArgs e)
{
frame = highgui.CvQueryFrame(ref VideoCapture);
if (frame.ptr == IntPtr.Zero)
{
timerGrab.Stop();
MessageBox.Show("??");
return;
}
imgMain = cxcore.CvCreateImage(cxcore.CvGetSize(ref frame),8,3);
picBoxMain.Image = highgui.ToBitmap(imgMain, false);
cxcore.CvReleaseImage(ref imgMain);
}
}
}
I have this code and when i step through the debugger to find the problem.
The problem i encounter is like this, it says that Cannot evaluate expression because a native frame is on top of the call stack.
when i break the debugger. the program stops at this point of the code. frame = highgui.CvQueryFrame(ref VideoCapture);
i dont know how to or what to revised in the code.
|
|
|
|
|
Hit F10 to step to the next statement in your code, and close any dialog boxes that have been opened by your code, and you'll be able to evaluate expressions.
|
|
|
|