|
|
Thank you Mike,
I have Invoke Methods.. I do not have any problem updating any of my form controls
only that after I called the invoke method.. ( when the user click on Start Button)
I can no longer click on any of form buttons like Cancel Button.
I would like to enable user interrupting whatever the program is busy working after the Start Button got clicked.
Thanks.
|
|
|
|
|
pnpfriend wrote: I can no longer click on any of form buttons like Cancel Button.
Then you have something "blocking" or code executing in the main thread that you perhaps "think" is executing in a background thread.
|
|
|
|
|
I know.. there might be something is totally wrong on what I am doing. but i just couldnt' see it. Yes.. I believe my function is running the BackgroundWorker thread.. but looks like i am not.
therefore I posted my code at first place. Please refer to my first post.
I worte down exactly what I did..
I'm trying to get the file and folder information using recursive.
since there are lots of files to browse I would like to allow the user interrupts by clicking Cancel Button. However, I can no longer click any button once the program gets into that function.
I used Invoke method too.
So what am I missing? what am I doing it wrong??
Please guide me, point me out my error.
Thanks.
|
|
|
|
|
pnpfriend wrote: So what am I missing? what am I doing it wrong??
Sorry to say but your code is a mess and very difficult to tell what you are doing. Maybe... just maybe this line
Invoke(new BrowseFFDelegate(BrowseFileFolder));<br />
<br />
Is sending you back to the UI thread where you finally do all the directory scanning work and therefore you are not even using the worker thread to do the work.
|
|
|
|
|
Is it returning to the UI Thread?
Invoke(new BrowseIFFDelegate(BrowseFileFolder));
It is working now for me after I added
Application.DoEvent();
I am not so sure if it is in BK worker or not anymore
but I can now click on cancel button.
Thanks for your help mike.
|
|
|
|
|
pnpfriend wrote: I am not so sure if it is in BK worker or not anymore
That's not a good thing. If you are going to put threads in a production application you better know what they and you are doing.
|
|
|
|
|
How can i search for certain word in contents of a file? I did that using File.ReadAllLines() but this takes a lot of time. Is there anyway to do that?
Thanks!
|
|
|
|
|
Streams let you look at a small chunk at a time, which is ideal with reading large files. Problem is, most of the examples I have I'm just reading bytes into a buffer of fixed length. If you're searching for specific text, you'll have to work out a way to read whole words. Depends on what you need to do, but Streams are the way to speed things up, read dependably, and conserve resources. Search google and/or CodeProject articles for information on Streams.
|
|
|
|
|
I have to finish a project in 7 hours and i don't have time to spend with searching on Google. I'll be thankful if you can help me
|
|
|
|
|
Alright, the following is an example of using a Stream to read 0.25 kb at a time.
public void ReadStream(Stream input) {
if (input != null) {
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = input.Read(buffer, 0, Length);
while (bytesRead > 0) {
bytesRead = input.Read(buffer, 0, Length);
}
input.Close();
}
}
But only you know what you need to do with the data, and I don't have time to work out a way to use a variable length buffer to ensure whole words are viewed. I'll leave that to you. Besides, this is either a school project that you need to do to get any benifit out of, or it's a work project that I'm sure you're not planning on sending me a check for doing the work for you. So... Good luck.
|
|
|
|
|
As a novel approach, you could also get a copy of Coco/R and build a simple tokenizer that has streaming built it. Then you just have to ask it for the next token.
|
|
|
|
|
You can put the contents of each file in a HashTable and load the files in at startup or when the first search is being done. Then you can search for words at O(1). This uses up quite a bit of memory though, and you still have to read the file at least once.
Open the file with a stream and read a line at a time, then use string.Split(' ') to split it into individual words and put the words into your HashTable (along with some data-structure that records line num, word num, etc...)
|
|
|
|
|
Ok another simple one here because ive got the XML writing correctly . so as you can see below i have string Value = ""; and in various button events i have string Value = "1";
quite simply i want a way to get the string to be reused so when i click button 1 the value of string to change inside the try { function .
Any ideas ?
private void ChangeStatus(object sender, EventArgs e)
{
try
{
string Value = "";
//xml reading code
CurrentStatus.InnerText = Value;
// xml writing code...
}
catch (System.Exception)
{
}
}
private void 1(object sender, EventArgs e)
{
string Value = "1";
}
private void 2(object sender, EventArgs e)
{
string Value = "2";
}
private void 3(object sender, EventArgs e)
{
string Value = "3";
}
|
|
|
|
|
Umm... Stop setting it to "" before checking to see what's in there. If you explained it effectively. If you set it equal to "" and then check to see what's in there, unless Microsoft needs to go back and do some work, it should always be equal to "".
|
|
|
|
|
I get a compiler error if i use string Value;
Error 1 Use of unassigned local variable 'Value'
Im getting confused here between actionscriptand c# any ideas on what changes i need to make ?
|
|
|
|
|
Hi,
if you want a single variable used by several methods, make it a class member, and dont
define it again and again in every method; like so:
class myClass {
private string myString;
public void Method1() {
myString="value1";
}
public void Method2() {
if (myString=="value1") Console.WriteLine("Method1 has been executed !");
}
}
The way you did it, every method had its own local variable, but they were independent
of each other. Read up on "scope rules".
|
|
|
|
|
Not sure if I follow but if you make your string a member of the class like
private string Value = string.empty. Then you can use it throughout the class.
God Bless,
Jason
Paul Conrad wrote:
Chuck Norris keeps the hamsters going whenever Chris is gone on vacation. Just stares them down and they keep the servers going
|
|
|
|
|
If I understand correctly, you have several buttons; "1" through "3" and "ChangeStatus"
The user clicks "1", "2", or "3" and then clicks "ChangeStatus" to effect the change.
The other answers about adding the field to the class will work, but I do it another way, the Button (all Controls?) has a Tag property, I use that to store the information.
On click "1" --> bChangeStatus.Tag = "1" ;
On click "2" --> bChangeStatus.Tag = "2" ;
On click "3" --> bChangeStatus.Tag = "3" ;
This could be changed to On click "1", "2", or "3" --> bChangeStatus.Tag = ((Button) sender).Name ;
Or if that's not the name, store the correct strings in the Tags of the buttons then
On click "1", "2", or "3" --> bChangeStatus.Tag = ((Button) sender).Tag ;
And finally:
On click "ChangeStatus" --> CurrentStatus.InnerText = (string) bChangeStatus.Tag ;
(Of course, always checking the type of the sender and Tag before trying to cast.)
|
|
|
|
|
Hi, I wanted to know if it's possible to integrate SQL queries into C# code using visual studio, and if so, how?
(I am very new to C#)
|
|
|
|
|
This is a very broad area. I suggest that you read up on ADO.NET and look at some of the excellent examples here on CP. If you are using Sql Server, read up on SqlConnection and SqlCommand classes. Have a look at articles on DataReaders/DataTables and writing custom data access layers (DAL).
For best practices, you really need to look at this[^] article by Colin Mackay.
|
|
|
|
|
Like Pete said, it is a very broad topic.
You can have SQL queries in your C# code when using classes like SqlCommand . You are probably better off using stored procedures because if the business logic changes, and the queries need to change to fit the business logic, then you have to recompile the code and redistribute the new code. For a small shop of one or two users, this is permissible, but imagine trying to get a shop of 500+ users to update to the new executable holding the new business logic change. One swift swoop inside the stored procedure takes care of it. I read that you are new to C# and stored procedures may be a big leap.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Like the other stated, the statement is to broad.
Try this Google[^].
Notice how I use 'C#' first then put in what every it is you are looking for.
Most of the time a link to CP comes up.
There are a lot of good articles here for this subject.
God Bless,
Jason
Paul Conrad wrote:
Chuck Norris keeps the hamsters going whenever Chris is gone on vacation. Just stares them down and they keep the servers going
|
|
|
|
|
thanks guys, I know I asked a pretty broad question. What I really need to do is bind a data-set in a gui to a table in a database
|
|
|
|
|
auloepid wrote: bind a data-set in a gui to a table in a database
That is pretty easy after you done it once.
Follow:
In Solution Explorer
Right click you Project -> Add -> New Item
Then in the Add New Item Window
Select DataSet and give it a name
Click Add
A new DataSet is added
While looking at the DataSet.xsd
Go to Server Explorer
Connect to the Database
Once the connected you can then drag and drop
What ever you need
God Bless,
Jason
Paul Conrad wrote:
Chuck Norris keeps the hamsters going whenever Chris is gone on vacation. Just stares them down and they keep the servers going
|
|
|
|