|
Dear robert Rohde
Thanks for advice, but filling ListBox is not my problem. I wanted it, just for an example of BackgroundWorker. Please if you have easy example about BackgroundWorker help me about this. I really want to know it's functionality.
Regards
-- modified at 14:03 Saturday 28th October, 2006
|
|
|
|
|
Hi,
as said you should find an example where no GUI manipulation is involved. You could make some heavy operations in the thread. Make a Form with a ListBox, two Buttons, a BackgroundWorker and a Progressbar and add the following code:
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
progressBar1.Value = 0;
progressBar1.ForeColor = Color.Green;
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
CalcPrimes(10000000, 10005000, e);
}
private void CalcPrimes(int start, int end, DoWorkEventArgs e)
{
for (int i = start; i <= end; i++)
{
if (backgroundWorker1.CancellationPending)
return;
bool isPrime = false;
if (i % 2 == 1)
{
isPrime = true;
for (int j = 3; j < i / 2; j++)
{
if (i % j == 0)
{
isPrime = false;
break;
}
}
}
int p = 100 * (i - start) / (end - start);
backgroundWorker1.ReportProgress(p, isPrime ? i : 0);
}
}
private void button2_Click(object sender, EventArgs e)
{
progressBar1.ForeColor = Color.Red;
backgroundWorker1.CancelAsync();
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
int primeNumber = (int)e.UserState;
progressBar1.Value = e.ProgressPercentage;
if (primeNumber > 0)
listBox1.Items.Insert(0, primeNumber);
}
This should be a typical scenario for the BackgroundWorker. Don't forget to bind all eventhandlers.
Robert
|
|
|
|
|
Hi
Dear Robert
I got error for below line in "CalcPrimes()" :
backgroundWorker1.ReportProgress(p, isPrime ? i : 0);
error says that : "This BackgroundWorker states that it doesn't report progress. Modify WorkerReportsProgress to state that it does report progress."
Anyway, So thanks to spending your time for solving problems.
Regards
|
|
|
|
|
Hi,
there are two properties on the BackgroundWorker you need to set to true. I think they are call SupportsCancelation and ReportsProgress or something similar.
Robert
|
|
|
|
|
Hello professor Robert
Program was solved successfully.
I found my problem and as you said i should set backgroundworker properties to "True".
Thank you;)
|
|
|
|
|
Hello,
In my Win Form, I have We browser control and sometimes I am getting error like following
:
" Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore
function. "
Can you please give me an idea why I am getting this error ?
Thanks
Emran
|
|
|
|
|
Hello
In what line of code do you get this error? And you said "sometimes"? What about "othertimes"? What do you do exactly to get the error -ie. under what conditions-?
PS.
Take a look at this link[^]. Specially the first hit.
Regards
|
|
|
|
|
Hi Nader,
Thanks for your information. Actually this error is coming magically sometimes.... not all the times... and I have no idea from which part of the code is throwing this error. I thought may be this error is some thing common to DataGridView, now it looks like, My guess is wrong. I will do some more research on it.
Thanks again
emran
|
|
|
|
|
I want to be able to hold the down arrow key to continue to scroll on a custom control that I've written.
How do I check for a key being held down? Is there a property or something to let a keydown event repeat itself?
|
|
|
|
|
implement keyDown event in your control and write your code there.
and where ever you are ebedding your control.create a explict handle for keyDown event for this control and link it with keyDown event which you have created in your control
sameer
|
|
|
|
|
sorry, that's not correct in this case.
|
|
|
|
|
Holding the key down and repeat rate is windows related. For example some users might disable this feature in their windows. Your control has nothing to do with it. All you have to do is handle the KeyDown event and implement scrolling for each stroke. When the user holds the arrow key down your program should receive multiple strokes, not just the first.
Regards
|
|
|
|
|
sorry, that's not correct in this case.
|
|
|
|
|
Why is that? I just made a small test:
1- Make any control that accepts focus
2- Make a ListBox for example
3- Handle the KeyDown event in the first control and in that handler call ListBox.Items.Add() for example and see if it will be repeated or not.
Regards
|
|
|
|
|
I found the snippet to handle an arrow key being repeated in a winform control.
The ProcessCmdKey method must be overriden to trap that key and the repeat message.
Normally the keypress event is the one that allows repeat keypresses by holding the key down. (This rate of repeat is controlled by the bios and the OS)
The keypress event does not trap the arrow keys.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 256;
const int WM_CHAR = 258;
const int WM_KEYUP = 257;
const int WM_SYSKEYDOWN = 260;
const int WM_SYSKEYUP = 261;
if (FromHandle(msg.HWnd) == this)
{
switch (msg.Msg)
{
case WM_KEYDOWN:
switch (keyData)
{
case Keys.Down:
int tag = (int)msg.LParam;
bool repeat = (tag & (1 << 30)) != 0;
if (repeat == true)
System.Diagnostics.Debug.WriteLine("********************");
if (this.SelectedIndex + 1 >= this.menuItems.Count)
this.SelectedIndex = 0;
else
this.SelectedIndex++;
|
|
|
|
|
Some quote from the MSDN[^] site:
"The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events." You should do Keydown's instead of ProcessCmdKey, that's what you are doing anyways...
bradsnobar wrote: switch (msg.Msg)
{
case WM_KEYDOWN:
Just do it on the .NET way.
bradsnobar wrote: switch (keyData)
{
case Keys.Down:
You could write your switch statement on OnKeyDown method:
private void yourcontrol_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case Key.Down:
...
}
...
}
Beside, embedding System const's in your code is not a nice thing to do. Microsoft could just change the values and your code will go to the outerspace.
ps.: Some words from MSDN[^]:
Notes to Inheritors When overriding the ProcessCmdKey method in a derived class, a control should return true to indicate that it has processed the key. For keys that are not processed by the control, the result of calling the base class's ProcessCmdKey method should be returned. Controls will seldom, if ever, need to override this method.
Diego Valdevino
|
|
|
|
|
planning to change out the sql statements i had in one of my application i developed but then my boss was wonderinf if there would be any security issue since persons would now have access to our sql statments by simply jus viewing the store procedures. and i was wondering if there was any way to prevent this
which leads me right back to wondering if i should jus make it be hard coded in the application
so basically my two questions are:
1. is there a way to protect my storeprocedures i thought of leting the server ask for the server account and this works in that the db's password protected but when i click to use windows authentication it allowed me to connect which makes me think that this can be used as a way of getting around me protecting the store procedure say any idea or i am way of on my approach
2. whats the difference in performance between hardcodding sql statems or using store procdures
Kenny Edmond
|
|
|
|
|
The difference in performance is typically large. Use the sql stored procedures instead.
If they can see your stored procs then they can see your data too. So which is more valuable? Probably your data.
This is a seperate problem that can be addressed with a good amount of security.
There are typically three layers of security...
IIS --> SQL --> Windows (File System)
Sometimes the SQL auth is integrated so SQL and file system are the same.
Your choice. But, I choose seperated for higher security, and integrated for ease of use.
|
|
|
|
|
1. From Books on line: "you are creating a stored procedure and you want to make sure that the procedure definition cannot be viewed by other users, you can use the WITH ENCRYPTION clause. The procedure definition is then stored in an unreadable form.
After a stored procedure is encrypted, its definition cannot be decrypted and cannot be viewed by anyone, including the owner of the stored procedure or the system administrator."
This is a rather extreme step to take, however. most hardcoded SQL statements can easily be viewed with a utility that dumps the strings tables in and executable, so IMO stored procs, even unencrypted, are no less secure than hard-coded sql statements.
To view your Stored procs, the user would satill need to be able to log in to the server, to view the strings in your exe, all that is needed is read access to the file...
2. As a general rule, stored procedures are more efficient since the excecution plan is precompiled.
|
|
|
|
|
Stored Procs are faster and you can secure them just like anything else in SQL. But another point is valid. It is much harder to do SQL injection attacks on a stored procedure.
|
|
|
|
|
OK - a lot of people here have stated that stored procs are faster than inline SQL, and indeed that was the case for quite a while. This is not always the case now.
One of the common misconceptions with Sql Server (version 7 onwards) is that it compiles stored procedures. Well - WRONG!!! It doesn't. What it does do, is cache execution plans for all queries that run through it (even ad-hoc ones). The algorithms that are behind this are very sophisticated and have gone through a lot of revisions/improvements by the Sql Server team.
Some SPs will be quicker than inline SQL, and some inline SQL will be quicker than SPs. Evaluate what works for you. Hint - dynamic SQL is generally faster inline than SP because you only send the result of the dynamic query generation to Sql Server, rather than having Sql Server try to dynamically populate parameters, etc.
Security.
Well, it is true that people can get at your stored procedures. But, this only applies to the level of security that you have applied to your DB. Look at using roles and authentication to lock down the database.
You can also lock down who can see your source code by implementing a robust security model for your organisation. Use a decent version control system to control who has access to the code. Limit the access on the directories where people check out/in the code to, so that only authorised users can gain access.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I need a simple software. I can develop it but I only know .NET (C# and VB.NET).
How I can write application for symbian 9.1?
If not what is name of symbian development IDE?
Thank you all
[C_O_D_3___4___N_U_L_L]
[C_O_D_3___4___N_U_L_L]
|
|
|
|
|
Code4Null wrote: Is it possible to write app. for symbian by VS2005 and C# or VB.NET?
Yes.
What is symbian?
led mike
|
|
|
|
|
Symbian is most popular Oprating system for many smartphones line Nokia (3250, e50,e70,3650 ....... )
|
|
|
|
|
No, The CLR/CLI have not been ported to symbian to my knowlege.
|
|
|
|