|
Hi all,
I want to build a progressbar that increment its value depending on other process like retrieving data from sql database.
For the first time it will take some time to retrieve table data and showed in dataGridView, so progressBar should express and represent for the time that it will take to retrieve data.
In the next time, retrieving data will be faster and progressBar will move faster as a result.
Thanks in advance.
|
|
|
|
|
Sounds difficult since you dont know how long it will take to get the data from the database. Perhaps you could first ask the database how many 'hits' your sqlquery would produce, and set the progressbars 'maxvalue' to equal 'hits'. Then finally retrieve one value at a time incrementaly and update the progressbar each time.
If it's the data manipulation that takes time, you'd get all the values in one call to the database, set the 'maxvalue' equal to rows retrieved, and then update the progressbar each time you've prosessed one row of data into the DataGridView.
If you want the progressbar to float in a dialogwindow over the parentwindow, you can make a custom form containing only the progressbar. Let the form take the maxvalue for the progressbar in the constructor and expose the increment method through a public method in the form. Then create the form before you start prosessing data, and call the increment method each time you've prosessed a row. You'd just close it through the eventhandlers when the progressbar reaches 100%.
Best wishes!
-Larantz-
|
|
|
|
|
Hi Larantz, could you show me a simple example. I am using SqlDataAdapter to retrieve my data, so how can I know the number of prosessed rows? Or do you mean that I will use sql query ( SELECT COUNT(*) .... ) ?
|
|
|
|
|
If the full query produces data rather quick, I'd just do that and initialize the progressbar with Minium = 0, Maximum = queryresult.Rows.
Then show the progressbar before starting to process the data, and use the ProgressBar.Increment(1) every time you've processed one row.
Should work out perfectly
-Larantz-
|
|
|
|
|
But how can I do it (get the number of processed rows) by using SqlDataAdapter ?
|
|
|
|
|
Microsoft used to do this with an algorithm that tended to infinity. In other words, during a search, the algorithm would almost - but not quite - reach 100% during the retrieve phase. Once the data was fully selected, the code would update the progress to 100%. Sometimes this meant that the progress would stay at 99% for a long time, other times it would reach 50% and then race through to 100%.
Note that if you want to do this, your other process must run on a different thread to the UI so that you can update the progress bar. There are lots of articles here on CP that tell you how to do this.
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.
|
|
|
|
|
Could you help me to find those articles?
|
|
|
|
|
Try this one.
http://www.codeproject.com/csharp/begininvoke.asp[^]
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.
|
|
|
|
|
Helow digitalhand,
Have u made it?
|
|
|
|
|
Hi All,
I want to send a Windows message to an application. However, the app is hidden (even to Task Manager).
I tried Process.GetProcesses() but the hidden app could not be found.
How can I attach to such a hidden processes.
Thanks in advance,
JC
|
|
|
|
|
Maybe you can try WMI, if you know its executable name?
Best,
Jun
|
|
|
|
|
Hello Jun,
Thanks for your idea about WMI. I do know the executable name of the hidden process but I am not familiar with WMI. My goal is to send some Windows messages to the hidden process. Could you provide me with some example codes or point me t;)o some clearer directions?
Thanks in advance,
JC
|
|
|
|
|
The following code snippet is from my article[^], which demonstrates how to
1) enumerate the object list and get the object you want (one object for each class) and
2) invoke GetOwner() method of the object under discussion.
When you have got your object, you may invoke its SendMessage() method with an appropriate argument list.
private: static void OnTimedEvent(System::Object* source, System::Timers::ElapsedEventArgs* e)
{
XLogoffThread::mut->WaitOne();
ConnectionOptions *co = new ConnectionOptions();
ManagementScope *ms = new ManagementScope("\\\\localhost", co);
ObjectQuery *oq = new ObjectQuery("select * from Win32_Process");
ManagementObjectSearcher *mos = new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection *moc = mos->Get();
ManagementObjectCollection::ManagementObjectEnumerator* moe = moc->GetEnumerator();
moe->Reset();
while(moe->MoveNext())
{
ManagementObject *mo = dynamic_cast<ManagementObject*>(moe->get_Current());
String *str[] = {"", ""};
str[0] = dynamic_cast<String*>(mo->get_Item("Name"));
if(str[0]->Equals("explorer.exe"))
{
mo->InvokeMethod("GetOwner",(Object*[])str);
if(!str[0]->Equals("SYSTEM") && !str[0]->Equals("System"))
{
CheckGUI(true);
}
break;
}
}
XLogoffThread::mut->ReleaseMutex();
}
Best,
Jun
|
|
|
|
|
Hi everyone,
I have an interface defined in a COM object that I need to implement using C# dll. If I register my C# dll for COM interop will that constitute a successful implementation of the COM interface?
Or do I need to implement the interface in VC++ then invoke the body of the implemented methods from my C# dll?
Sorry if it seems s silly question, I am quite new to Windows programming, as I was a Java programmer before I start on this project.
thanks very much guys,
me
|
|
|
|
|
In Visual Studio, you need to Add a reference and then select the COM DLL in the COM section of the Add Reference dialog. VS will create a wrapper class for the DLL that will allow you to interact with the DLL as though you are doing everything in C#.
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.
|
|
|
|
|
Would this wrapper class be a seperate dll file? So would I have the original COM dll, this wrapper dll and my C# object dll? Or would the wrapper be part of the C# compiled dll?
thanks, this is very helpful..
|
|
|
|
|
The wrapper is effectively generated as a .NET stub code. This means that the compiled DLL will contain the code that is necessary to call into the COM DLL.
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.
|
|
|
|
|
That would be ideal, to have the compiled DLL contain all necessary components implement the interface defined in the COM dll.
But when I add the reference to the com DLL (in my case its called xesession.dll) and write my C# code implement against it and build the solution it creates a file called interop.xesession.dll . Isn't that the 'wrapper' ?
Or do I need to turn off 'interop' or something?
thanks again..
|
|
|
|
|
And also, if the interface I'm implementing in C# is to be instantiated and used by a non .NET (VB6) application will my VB6 app recognize the object even though the object is managed and the VB6 app is not?
|
|
|
|
|
Hi all,
i am using the API :
[DllImport("user32.dll")]public static extern int GetCaretPos(ref Point lpPoint);
what i'm trying to do is the show contextMenu above the KB cursor.
it's working good with MSN messenger and Notepad (the function returns the cursor's possition in the active window)
but, in other programs like:MSWord,Yahoo messenger it returns(X=<the currect="" x="" location="">, Y=0)
how is it possible?
Sincerely,
Ran.
R.Z
|
|
|
|
|
How do u work with MSN messager and notepad, i want to get your some source code.
Please ,Thank u very much
Sorry ...
|
|
|
|
|
Thats the code that give you on msn and notepad.
i'm looking to work also on Word and Yahoo...
private Point getCaretLocation()
{
IntPtr hFocus = (IntPtr)GetForegroundWindow();
IntPtr hFore;
IntPtr id=IntPtr.Zero;
if (hFocus != IntPtr.Zero)
{
hFore= (IntPtr)GetForegroundWindow ();
AttachThreadInput((int)GetWindowThreadProcessId((int)hFore, id),
GetCurrentThreadId(), 1);
hFocus = (IntPtr)GetForegroundWindow();
Point mypoint=Point.Empty;
GetCaretPos(ref mypoint);
Console.WriteLine(mypoint.ToString());
ClientToScreen (hFocus, ref mypoint);
return mypoint;
}
return Point.Empty;
}
R.Z
|
|
|
|
|
Im using access database to store some customer information.
I have a table with an autonumber field.
I want to get the value of the autonumbered field, for the last added record in that table? So i can use it as my Customer ID for the next entry of customer details.
if the last generated autonumber is
Ex:
100 ->
the next customer id should be 101, can anyone please help or can point me to the right direction :)
how do i do it using ado.net? Just learning c# and ado.net :)
+============================================================================
Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Don't use the pre tag on the message. The font isn't that easy to read, and the text doesn't wrap.
After you insert a record, use the query "select @@identity" to get the id that was created for the record.
---
b { font-weight: normal; }
|
|
|
|
|
thanks Guffa for the reply ill check it out
Sorry for the pre tag
|
|
|
|