|
My timer callback delegate may decide to dispose the timer if certain conditions are true.
Do i need to lock(this) before doing so since another callback may be executed at the same time?
thanks alot !!
more details if you have the time:
when event x happens, i construct and start a timer with the callback function Func. Func checks if there are items in a list:
If there are items it handles the items
else it disposes the timer.
Func will occur in a timely fashion till list will be empty - and timer disposed.
If event x will happen again and the timer already exist - do nothing, if timer doesn't exist - construct it again.
|
|
|
|
|
Hi,
if it's a Windows.Forms.Timer its handler runs always on the GUI thread, so it can't reenter.
if it's a Threading.Timer or Timers.Timer it may reenter before it finished an earlier call.
Anyway, if you may need the timer again later on, why dispose and recreate it? a timer
is not that expensive, you could just Stop() it, and later Start() it again.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Luc, thanks for answering me. i use Threading.Timer and i didn't see any Stop \Start methods.
I found only ways to set it to infinte time, thus disabling it. But then when i need to check
whether it's already disabled, the check seems akward - i have to check if it's set on infinte time.
Is there an equivalent of stop and start that i missed?
thanks and have a great day
|
|
|
|
|
Hi,
Threading.Timer has Change() method; the other two timer classes do have a Start() and
Stop() method, and an Enabled property, so they might be more appropriate for your purpose.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
I have currently a problem with my ListBox.
It's the first time I implement a specific draw item function
The problem is that when I clear my ListBox the draw function is still called !!!
I dont understand why, if I clear the list I shouldnt have any items in the list why is the draw function called ?
Thanks for any help !!
|
|
|
|
|
When the DrawItem event is fired and there are no items in the ListBox, then you really just need to draw the background. The DrawItemEventArgs[^] has an Index property which tells you which item you are drawing. If this value is -1, then you are not drawing an item (probably because there are none). In addition, the State property tells you what you need to draw.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi.
Im trying to make an automated gallery browser that can scroll through web pages and download all the images off them. It is currently working, using a webBrowser control. I have a list of all the images on the page in a listbox on the side, each with a thumbnail preview image. However, i am on dial up (laugh and get it out of the way), and the way the application currently works is to download the url to the browser, extract the img tags from the source code, and download each image as a bitmap. This takes ages as it has to download each image twice, once in the web browser and once from the url of the image.
I am wondering if there is anyway to extract the images from the webBrowser control so i dont have to download them twice?
I have played around with the webBrowser.DocumentStream, but cant work out how to get the images.
Any help appreciated.
-- modified at 18:23 Sunday 25th November, 2007
|
|
|
|
|
Just an idea, not sure it will work, not sure you will like it:
tell Internet Explorer to not show images (uncheck Tools/Internet Options/Advanced/Multimedia/
Show Pictures). That way the browser should not follow the IMG tags automatically.
I reckon you'd better forget about the browser control, and do HTTP calls yourself,
using the System.Web namespace.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
The browser control is embedded in a form, its not using internet explorer.
Guess i will have to start doing some research into the HTTP Requests.
I knew taking the easy way would catch up with me in the end
Is there anything good to be said about using the AxSHDocVw.AxWebBrowser, or is it similar to the Windows.Forms.WebBrowser?
|
|
|
|
|
Did you try what I suggested?
AFAIK WebBrowser uses the settings set in IE.
I expect WebBrowser and AxSHDocVw to be very similar.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Using HttpWebRequest is actually pretty easy, in around 8 lines or something like that, you will have a stream or similar of the html code for the page, which you can then just search for the img tags. I'll just go grab some code...
using System.Net;
...
HttpWebRequest Pie = (HttpWebRequest)WebRequest.Create("http://www.pie.com");
HttpWebResponse response = (HttpWebResponse)Pie.GetResponse();
Stream pieStream = response.GetResponseStream();
SR = new StreamReader(pieStream, true); 8 lines, 4 lines, its the same thing!
Anyways, then you can just read the text using the stream reader.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Thanks for the pointer Luc.
The Undefeated: Code snippet helped a lot
I have the stream of the web page. Does that contain the images in the page as well?
I am using a webBrowser control to experiment. I have set it to give me a message whenever the FileDownload event occurs, and am getting differing numbers of messages per page, as expected. However i cant work out what files the FileDownload event is occurring for.
Is there any way i can extract the the images on a page from the webpage stream or am i on the wrong track?
|
|
|
|
|
Hi There,
Can anyone tell me how to get the color of a string?
E.g.: I am passing a string to a function. The function needs to return the color of that string.
public Color GetColor(string);
I am extracting this string from a RichTextBox line.
Thanks in advance.
-----------------------------------------------
"Don't crib about your job. Only 1% are doing something meaningful and I have never seen any of them."
|
|
|
|
|
Hi,
a string has no color, it only holds characters.
an RTB can show a string with extra attributes such as font style, color, e.a.
You can get or set the color of some text INSIDE an RTB using RichTextBox.SelectionColor().
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
thanks a ton!!!
|
|
|
|
|
Hi all,
I am working on C# project using C# 2.0. I have a DataGrid that contains 10 rows and at runtime I insert one more row at DataGridView.Insert(0,1); in my next step, I want to delete the row from DataGridView at DataGridView.RemoveAt(9) // Index 9 is the last row in the grid. But, I am not able to delete the row. I am getting following exception: System.InvalidOperationException:Uncommitted new row cannot be deleted. at System.Windows.Forms.DataGridViewRowCollection.RemoveAt(Int32 index)
Please help if you know the solution.
Thanks in advance for your help.
A.Asif
|
|
|
|
|
The easy way to delete the row of the data gird is to get reference of the current row. Note: I assume that Grid is bound to a BindingSource names "bindingSource". Put the following code inside the event of Delete button.
DataRowView DRV = bindingSource.Current;<br />
if(DRV!=null)
DRV.Delete();<br />
Regards
|
|
|
|
|
1st of all, let me tell you that I am new to Windows (Desktop) Applications. I am basically ASP.NET developer and have worked much in this field. Now I am trying to work on windows applications and facing lot of challenges. One of which is described below.
IF YOU HAVE NOT ENOUGH TIME TO READ THIS ALL, JUST GO TO THE END AND READ MY QUESTIONS IN A FEW LINES. This may not clear, why I need this.
Goal
-----
Create the window for data input. On Ok, record should be entered in data set On Cancel, record should be discarded. User can enter as many records as required and also can update some existing records. By navigating to each records, user can cancel the changes of each record. To commit the changes, user have to click Save button. To reject the changes, user have to reload all data.
Design
-------
I am working on C# project. I've created the Typed data set. Windows form is populated with required controls (Text Box, Check Box only for my current window), one Binding Source control bound to the table of Data Set (Which automatically created Table Adapter for me. I've bound the form controls (Text Boxes) to the Binding Source's properties (Automatically created by designer). I've also created navigation controls manually.
Run time behavior
------------------
Some records already exist in the database, so when Application is run, records are automatically displayed in the controls(by fact they are bound). Navigation controls(Next,Previous,First & Last including the record position and total records) are working properly and displayed contents are changed properly.
Problems
---------
1. How I can add new record?
Binding Source's Add method requires parameter as object to be inserted. What object I can pass? and how to get / construct that object?
Binding Source's AddNew() method is working (NOTE: I am calling AddNew method of the BindingSource in a method, where I initialize all the controls(texboxes) of the form(record) to initial values. TextBoxes are also assigned Empty string). Record pointer & navigation controls are updated. At this level, It seems everything is ok. When Add New button is clicked (To add an other new record) exception is thrown saying [columnname] do not allow null value.
To overcome this, I changed the way to enter the new record. Now I enter the new row directly to the DataTable in the dataset, rather than adding to the Binding Source by calling its AddNew() method. After adding I change the position of the Binding source to the last record of the data table. The problem with this is, the row is already entered by bypassing some business rules (validations).
How I can cancel the changes of each record ?
-----------------------------------------------
On the cancel, I am checking the row state of the displayed record (current record). If its new (Added), i am simply deleting the record. This is working.
When I navigate to the existing record, and I change some values in text boxes, and then try to Cancel the changes. Nothing is changed? (old values are not shown in controls). I put the condition to check, On Cancel click, if current record's row sate is Modified, I am calling CancelEdit() method of the Binding source (Same buttons Added state is handled correctly as i mentioned above). While debugging, I encountered that some times row sate is shown Detached and some times Modified. I put both conditions with OR (||) operator, surely CancelEdit() method is called but still control is displaying new values (means changes are not reverted at control level). I tried to call EndEdit() method of current row, Before and after CancelEdit, but still no luck.
One more thing, on FormClosing event of the window, i am checking if any changes were made to the records and ask from the user Yes=Save,No=Discard,Cancel=Dont close the window. After editing a text box and trying to close the window, doesn't display the dialog box to ask. Why changes were not made to the Table in Dataset?
Let me confess that, while working on this, I canceled the new added rows, which I mentioned above that its working fine. I didn't try to save new added rows. so I don't know while saving, it'll throw any exception or not.
phewwwwwww!!!!
Summary of the problem and help needed
----------------------------------------
Is there easy way to add/update records with cancel (changes) functionality in Windows forms? Note that there are many fields/columns, so Its not preferred to use Data Grid.
How to cancel changes of the updated record by using Binding Source ?
Am I going to wrong direction ?
Regards
|
|
|
|
|
i have to fill SQl 2000 tables from window forms the problem is when filling the 1st table i load the database table in a datset in the form load event now when filling the second table what will be the possible event to fire that it load the second table in the datset
sas
|
|
|
|
|
I think its not clear what you exactly need. I am sorry at least for me, its not clear. Would you like to explain please ?
|
|
|
|
|
sir the problem is i am working on a HR database u have worked on web forms the application consists of 4 forms every form is associated with two tables in sql2000 the question is that when the user open the application in the form load event i kept the dataset filling method for the first table now when user switch on to the next table what will be the event to load the second datatable in the datset
sas
|
|
|
|
|
well sorry to say dear Sajid, you've failed to describe your problem. HOW?
1st of all, you are talking about the FORMS of the application, on other hand you are talking about switching to next TABLE
I think there is no any TABLE control in C#.NET.
If you are talking about FORMS, talk about the controls on the form.
So now I am asking, as you said, every form is associated with two tables, How these 2 tables you are displaying on the form? i mean which controls you are using to display the data of the Table ?
This way we can know and figure out what events are available for that control. NOT THE TABLE..
I hope now you understand what I mean to clearify
Regards
|
|
|
|
|
hi.
I am writing a program with c# and sql as database.
i have a MDIform as startup form which one of my form(frmMain) opens with it.
in frmMain i have a combobox which is filled with data from CityTable. it means that I used Value Member and Display Member to fill it.
when I press the button "Add City" on MDIform another form opens and i can add a new city.
the frmMain still is open.
my problem is here how can I update city Combo box in frmMain?
please help me.
i have asked from a few persons and they gave 2 solutions :
1-raise an event
2-open City From using showDialog()
now please tell which one to choose and how?
|
|
|
|
|
As per my knowledge, Do this.
Make the data source(Table containing the Cities) of Combobox, publicly accessible by declaring in the mainForm a static propertly which return the data table of cities.
In the dialog box, where you add new record, access the data table of mainForm and add city in it. It'll automatically shown in combo box because its already bound to that table.
Regards
|
|
|
|
|
thanx for answer
appreciate
|
|
|
|
|