|
It's actually very easy. There are two kinds of timers in the .NET Framework:
- Windows Forms timers (
System.Windows.Forms.Timer class), which you drag in the desinger to your form, set some properties, and write the code for the Tick event handler, and that's it. For your situation, the problem is that if the process is long, it will block your UI thread and your main form will not be responsible. - Thread timer (
System.Threading.Timer ). I have never used this one, but from the docs[^] it seems you set a timer, without requiring a form, that will run on another thread. So, your form keeps working normally while another thread does your processing on the background.
I believe the second one will suit your purpose better. But, as I have never used a System.Threading.Timer , I can't be of more help, since all I know is the same as you, what is included in the documentation.
If someone knows better, feel free to correct me please!
Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Thread.Sleep should work. What did you pass as the parameter? For 10 minutes, it should be 10 * 60 * 1000. But remember that Thread.Sleep would be less efficient than a signaling mechanism as Thread.Sleep would cause the Thread to use up CPU time...
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Thread.Sleep() causes "busy wait", where the thread uses up its quantum of CPU time doing nothing. Waiting for a signal (or in general, any OS synchronization mechanism) causes the thread to be context switched for another immediately. This obviously results in performance benefits as other threads get a chance to run in the time that a "sleeping" thread would have spent doing nothing.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have a collection of items. Each item has some events. I am exposing the collection through a property which shows up on the propertygrid of the form. I can edit the collection and all the persistance to the code is allreay taken care of.
One problem remain which I can't solve. I can't edit the events of each item like you can normaly edit with the form's events or the control's events. The collection editor don't show the event tab.
The main goal is to edit this collection like you edit a menu and it's items. You can edit the menu items events. My class is not for visual porpose and is been used on components, not just forms, so the solution of using a collection-Based Controls with Rich Design-Time Support http://www.codeproject.com/csharp/collcontrolsrichdes.asp
is not valid for this case.
Thanks in advance. Any help will be appreciate.
|
|
|
|
|
Hello all,
I Work with active X control i added it with " Add Reference" and i used the functions that it exposed to me in my code did it need any installtion code to setup or just i add a refrence to it in my code only.
Regards,
Hay
|
|
|
|
|
No need for any separate installation code.
The basic procedure for using ActiveX control in your Visual C# code is as under:
1. Add a reference to the type library containing the ActiveX control.
2. If you want to take advantage of the designer, add the ActiveX control to the Toolbox by customizing the Toolbox.
3. Now, drag an instance of the ActiveX control from the Toolbox to your designer to add it to your project at design time. This will add the necessary code to instantiate the control in your project. Alternatively, you can declare and then instantiate the ActiveX control in code and add it dynamically to your application at run time.
|
|
|
|
|
I am trying to crete a method that will convert an improper fraction to a mixed number...
I am not sure how about how to acomplish this. I know I can get the remainder with the modulus operator (%), but I am not sure how to get the quotent.
Any insight would be appreciated.
thanks
|
|
|
|
|
One method to get the quotient (or the whole number portion of the improper fraction) is to use a function such as under:
public int GetWholeNumber(int numerator, int denominator)
{
int wholeNumber = 0;
int tempNumber = Numerator;
while(tempNumber >= Denominator)
{
tempNumber -= tempNumber ;
wholeNumber ++ ;
}
return wholeNumber;
}
Or, alternatively, you can also try the following method:
int Numerator = 57 ;
int Denominator = 9;
int wholeNumber = (int) (Numerator / Denominator);
|
|
|
|
|
Hi!
I'm building a grid control which contains a grid of cell controls. Each cell is supposed to contain another control. Everything works fine except the design-time behaviour which I have two problems with. The first is to draw adornments on the cells, which are another control type contained within the grid control (sort of the same as a panel control)..
[Designer(typeof(LayoutGridDesigner))]
class LayoutGrid : Control
{
ArrayList<gridcell> gridCells;
...blabla...
}
[Designer(typeof(GridCellDesigner))]
class GridCell : Control
{
}
I've tried to make both the GridCellDesigner and the LayoutGridDesigner to paint a dotted line around (inside the border of) the GridCell. The gridcell won't paint anything - I expect this to be because child control don't seem to paint adornments. When trying to paint the adornments with the GridLayoutDesigner the gridcell keeps on repainting...
The second thing I want to do is to make the gridcells able to contain other controls. This works by making GridCellDesigner inherit from ParentControlDesigner instead of ControlDesigner, but as with the adornments it doesn't work when the gridcell is a child control..
Any suggestions?
|
|
|
|
|
HI
Need help, Does anyone know how , which code i should use to open an authentication window from the code? when using webclient features, Im talking about the same window that opens in the Gmail Notifier on the startup , the one that you get when trying to navigate to a protected 401 page.
i tried using the httputility class , but no luck .
please HELP!!!
Thanks a lot
MOshe.
thanks , moshe bar-oz
|
|
|
|
|
You cant, the IE auth window is part of IE. What you can do however is create your own dialog box with username/password. Create a network credential object from the username and password and assign it your webclient object's credentials.
Ryan
Ryan.
|
|
|
|
|
hi
thanks for replying , i think I can , there are objects of IE ??
So how Gmail doing that in their code?
thanks , moshe
|
|
|
|
|
Hi All:
Sorry, this doesnt really belong in this forum but I dont know which forum I can put this in.
I want to have a batch script that insalls a windows service with local system account priviledges. I know that if I install something I can just use the installutil program to do it, but how do I get it to have the system account priviledges?
Secondly, how do I programatically install a scheduled task?
Thanks a lot for your help,
Jim
Did I post well? Rate it! Did I post badly? Rate that too!
|
|
|
|
|
In your installer you can set the account that your service will install under.
Esmo2000 wrote:
Secondly, how do I programatically install a scheduled task?
Since you are running a service, you can just create a timer and execute anything you need to. If you specifically need a scheduled task then there are some articles on CP that will show you how to do it.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
andy brummer wrote:
In your installer you can set the account that your service will install under.
Sorry, this is a stupid question, but I don't see where I can do that. Can you give me hint what I need to be doing?
andy brummer wrote:
Since you are running a service, you can just create a timer and execute anything you need to. If you specifically need a scheduled task then there are some articles on CP that will show you how to do it.
I wish it were that easy, but my program is runnig asynchronously. I'm worried that the two might happen at the same time and I dont want two threads to be running at the same time in this program. Would you have any suggestions for stopping this from hanging on the next message?
The program structure for that is just a function that resembles:
set messageEventHandler functionName;
functionName
{
getMessage();
doBlah();
getNextMessageWaitIndefinitely();
}
Did I post well? Rate it! Did I post badly? Rate that too!
|
|
|
|
|
how do i access datapicker.value through Control reference
i cant get control.value
|
|
|
|
|
can you rephrase your question ?
Shardool Karnik
Lead Software Engineer
Compass Technologies, Inc.
http://www.compasstec.com
|
|
|
|
|
You have to cast the reference:
DateTimePicker dtp = ctl as DateTimePicker;
DateTime value = DateTime.MinValue;
if(dtp != null)
{
value = dtp.Value;
}
else
{
} I hope this helps!!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
(New C# user here)
I have a binary registry value (an encoded password) that I need to retrieve and pass as a string to the decoder.
The (example) registry value is:
01 00 02 00 03 00 00 00
What I need to end up with is a string with the bytes in each char reversed like in this hex literal:
"\x0001\x0002\x0003\x0000"
RegistryKey.GetValue("MyValue").ToString() does not do the 'endian conversion on each char that I need. (In fact, I can't really tell what it's doing! Probably some fancy stuff related to locale...)
How can I get at this binary registry value as an array of bytes and then convert it to my desired string?
Thanks!
--
Ray Marron
|
|
|
|
|
I figured it out:
<br />
string sPass = "";<br />
object oPass = rk.GetValue("Password", null);<br />
if (oPass != null) <br />
{<br />
byte[] aPass = (byte[])oPass;<br />
int i, j;<br />
for (i = 0; i < aPass.Length; i += 2)<br />
{<br />
j = aPass[i] + (aPass[i + 1] * 256);<br />
sPass += (char)j;<br />
}<br />
}<br />
|
|
|
|
|
Hi all,
My application loads user selected images in Imagelist for thumbnail display in Listview...Here's the code that i use do that..
ImageList.Images.Add(imageToLoad,Image.FromFile(imageToLoad));<br />
LstVwImage.Items.Add(imageToLoad,imageToLoad);
So far so good, When user selects any image from listview and selects Delete button, I want it to remove items from listview and imagelist and delete physical file corrosponding that path, here's the code I am using...
<br />
LstVwImage.Items.RemoveAt(deleteIndex);<br />
ImageList.Images.RemoveAt(deleteIndex);<br />
FileInfo fi = new FileInfo(deleteFile);<br />
fi.Delete();<br />
Unfortunately its not able to delete file, saying "File is being used by another process"...Its not permission error as I am able to delete any file if its not loaded in imagelist or listview...
Either I'm getting crazy or stupid error!!!
Pls throw some light on this!!
Regards
MaulikCE
"Every obstacle presents an opportunity to improve our condition."
|
|
|
|
|
I guess it is that the image hasn't been garbage collected yet, so the image file isn't closed..
You should try to call the Dispose method of the image before the delete function is called..
|
|
|
|
|
I'm still fairly low on the C# learning curve, especially with respect to WinForms. I've been searching all over the place for a suitable answer to my requirement, so far to no avail. Time to beg here.
Consider a typical 2-column ListView. When you select one of the rows, I want the item in Column 2 to turn into a DropDown to allow selection from a fixed list. The unselected rows simply show the text previously selected from the dropdown.
So far I've found hints that I'll need to do some sort of subclassing of the ListView, but nothing further. A code sample would be outstanding if possible. In fact, I see this as the kind of thing that'd make a good CodeProject article.
Thanks in advance for any advice.
Brad.
|
|
|
|
|
b_p_smith wrote:
I see this as the kind of thing that'd make a good CodeProject article.
You bet! It's not easy at all what you're trying to accomplish. The ListView has a GetItemRect method to get the rectangle of the item (the selected item), but not for a specific subitem, so you would have to get the width of each column from the Columns collection.
And, what happens if all the columns are wider that the control? and if the ComboBox is in a column scrolled out (horizontally)? Or if the selected item is scrolled out of view (vertically)?
You have the EnsureVisible method, but not something that will tell you if the item is visible or not.
[EDIT: I know I didn't solve your problem, but I hope to have given you a few pointers at least.]
Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|