15,896,606 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Martijn Kok (Top 54 by date)
Martijn Kok
21-Jan-14 2:24am
View
Hello Rahul,
It's actual a good question. I'm not sure if my technical knowledge is good enough to explain it clearly, but I hope my explanation will give some indication for you to search for more information on this topic.
A thread is more or less a seperate piece of executing code. Every program has at least one thread in which the program executes. Each thread has exactly one current line of execution (the yellow line when you are debugging your code in Visual studio). A thread does more than that. I also does something with memory management (I don't know the details). A thread owns the objects which are created in that thread.
Your code can run more than 1 thread. When your start a BackgroundWorker a new thread is created. Not Always the threads know of each other existance. Their life time might be different. In this case of the BackgroundWorker the background worker only exists as long as the background worker executes. As soon as the backgroundworker is completed is stops existing.
This might create a problem in memory management. When the backgroundworker dies, the objects it owns die too. If it was allowed that one thread sets object in another thread this would cause a problem.
There are several solutions to this problem, which all involve calling the other thread first an than setting the object. This can be done using an Invoke (in WinForms). WPF uses something called the Dispatcher object. In the background worker you can use the ProgressChanged event.
Martijn Kok
15-Nov-12 4:38am
View
Hi Vasanth,
I'll send it in a view. The playlist part of the code is missing. I've never seen the actual code behind the ListView (I never really used a ListView in programs I wrote).
Due to the missing of part of the code, I have made guesses about parts, but I think you could fit it into your code.
Regards
Martijn
Martijn Kok
13-Nov-12 0:40am
View
Hi Vasanth,
My mistake. Ater calling DoWaiting, I didn't break the execution of the code (which would result in calling the Thread.Sleep(2000) and thus waiting for 2 more seconds). Change the code to
ResetTime();
if (DoWaiting())
{
e.Cancel = true;
break;
}
Regards
Martijn
Martijn Kok
12-Nov-12 11:39am
View
Hi Vasanth,
I think I have a solution. I can't test it though and thus I'm not sure if it will solve issue 1.
First of all add the following code:
private int timeInMilliSecondsRemaining = 0; //Initialize the time at 0.
private bool DoWaiting()
{
while (timeInMilliSecondsRemaining > 0)
{
Thread.Sleep(200); // 200 milliseconds
timeInMilliSecondsRemaining -= 200; // substract waited time from timeremaining
if (backgroundWorker1.CancellationPending)
{
return true;
}
}
timeInMilliSecondsRemaining = 0;
return false;
}
private void ResetTime()
{
// Only reset time if the current time has been finished, otherwise resume
if (timeInMilliSecondsRemaining <= 0)
timeInMilliSecondsRemaining = Convert.ToInt32(listview_playlist.SelectedItems[0].Tag.ToString());
//timeInMilliSecondsRemaining = Convert.ToInt32(txtboxSleep.Text);
}
Secondly change part of the loop into:
backgroundWorker1.ReportProgress(i * 100 / count, j);
//Thread.Sleep(2000);
//if (backgroundWorker1.CancellationPending)
//{
// e.Cancel = true;
// break;
//}
ResetTime();
e.Cancel = DoWaiting();
The code does the following. To pause you need something to pause. In the former code the backgroundworker did wait the required seconds and then checked to see if a cancellation was pending. So it was inpossible to stop halfway. The DoWaiting method checks every 0.2 seconds if a cancellation is pending.
To check the time remaining I added a int with the time remaining in milliseconds. When the time remaining reaches 0, the waiting will be finish. DoWaiting returns true if the pause button has been hit (assuming that your pausebutton will cancel the background worker).
To set the time remaining I added the ResetTime method. It will take the time form the playlist (you might need to mulitply the seconds with 1000, i forget that).
Concerning Issue 1 this also might be solved. When you push the start button the reset time function will check if there was a time remaining and the code will continue where it left. If you don't want this funcionality, then remove the 'if (timeInMilliSeccondsRemaing <= 0)'
I hope it will work
Regards
Martijn
Martijn Kok
12-Nov-12 10:27am
View
Deleted
Hi Vasanth,
I think i have a solution, although I'm not sure that is solves issue 1. Unfortunately I can't test the code.
First of all add the following code
<pre lang="c#">
private static int timeInMilliSecondsRemaining = 0; //Initialize the time at 0.
private bool DoWaiting()
{
while (timeInMilliSecondsRemaining > 0)
{
Thread.Sleep(200); // 200 milliseconds
timeInMilliSecondsRemaining -= 200; // substract waited time from timeremaining
if (backgroundWorker1.CancellationPending)
{
return true;
}
}
timeInMilliSecondsRemaining = 0;
return false;
}
private void ResetTime()
{
// Only reset time if the current time has been finished, otherwise resume
if (timeInMilliSecondsRemaining <= 0)
timeInMilliSecondsRemaining = Convert.ToInt32(listview_playlist.SelectedItems[0].Tag.ToString());
//timeInMilliSecondsRemaining = Convert.ToInt32(txtboxSleep.Text);
}
</pre>
Martijn Kok
12-Nov-12 10:16am
View
Hi Vasanth,
I hope i have a solution. Not sure if it also solves issue 1. I have put the code at the end of this thread.
Martijn Kok
12-Nov-12 2:40am
View
Hi Vasanth,
I had some hard time getting into the question again. I think I understand your questions.
Issue 1: after pause you want the paused item to continue? And if so, do you want to restart the timer or continue. For instance if you want to play for 25 seconds and you have played 6 seconds already. Should it restart at 25 seconds or continue with the remaining 19 seconds?
Issue 2: if you enter another time (lets say 25 seconds, your playlist should run for 25 seocnds.
Martijn Kok
9-Nov-12 9:45am
View
Hi Vasanth,
I wasn't able to answer earlier. I have been working a lot the past few days.
I'll look at your questions this weekend. It has been a while and I have to study the code. I'll hope I will be able to answer your questions.
Martijn Kok
25-Sep-12 3:08am
View
Thanks :)
I have read it partally and it looks very promissing. I'm definitely going to test the demo code. Using Visual Studio components do have my preference over third party components.
Martijn Kok
21-Sep-12 8:56am
View
Good you discovered why ZIPPACKAGE wasn't working. I hope you find a good solution to work with zippackage.
Martijn Kok
21-Sep-12 7:38am
View
When I google the error message (at least the first sentence) I keep finding another reason for this error.
http://go4answers.webhost4life.com/Example/visual-studio-2010-not-working-27110.aspx
.
Is your code on your local hard drive or on a network drive? If it is on the network drive you might be interested in the above link. There is a mention how you could configure Visual Studio to trust network drives.
Martijn Kok
21-Sep-12 3:40am
View
Interesting question :) I'm not sure if two way binding is possible. It was in your code so I assumed it was possible. With a normal button it is not. At this moment there is no use I can think of why two way binding is possible.
As for the CheckBox it is kind of hybrid. It can both be used as something to display state (IsChecked) and to be used as a button (cuase it's derived from ButtonBase).
I'll try to study Command in the CheckBox after work. I have never used the Command of the CheckBox so I wonder how it works. Maybe the Command doesn't support TwoWay at all. And if it does I do wonder what it's use will be.
Martijn Kok
21-Sep-12 2:04am
View
Unfortunately screenshots are not supported. If your colleague is talking about a build order that would suggest that there are more than one project in your solution.
I sometimes build all the projects one by one in the right order, but I don't think it will solve the problem. But you could try.
Maybe there is one otherway. Intellisense normally puts the right namespace code in your XAML. Have you typed it manually or have you used intellisense. What you could do to test it, is defined a new namespace (for instance xmlns:test). As soon as you are starting to type "clr-namespace" intellisense will start. Select the namespace you need from that list. There are to possibilities.
1) the namespace (for instance ABC.XXX.YYY.Silverlight.Controls) is there. Select it. If it doesn't include a ;assembly= then it is not needed. If it is there, it is needed, and you should replace it with the xmlns:local
2) if you can't find the namespace in the list something else might be wrong.
Martijn Kok
21-Sep-12 1:39am
View
Every binding has a default mode. The Modes are TwoWay, OneWay (from source (ViewModel) to target (View)), OneWayToSource (from target (View) to source (ViewModel), Default, Once (only once update on initialization). Binding to a TextBox's text property is TwoWay by default. Binding to a TextBlock's text property is OneWay by default.
I assume binding to a Command is TwoWay by default. At least I never explicitly define it. It was in your sample code. It worked, I guess I was lazy, so I left it there. :) You could remove it. In case of the IsChecked I defined it explicitly just to be sure, but probably IsChecked is also TwoWay by default.
Martijn Kok
20-Sep-12 9:42am
View
Then the ABC.XXX.YYY.Silverlight is local and the adding of assembly=(...) won't solve it.
I'm not sure if I can be of any assistance, because I can't reproduce the error. Have you seen the link in a previous reply (the one to stackoverflow.com)? If I read it well there were others having the exactly the same error message with a local namespace. They describe a not so common combination which produces the error.
I hope you'll find the cause of the error.
Martijn Kok
20-Sep-12 7:34am
View
I think I haven't explained it well enough. I wasn't talking about a folder in the Windows Explorer (as being part of Windows). I was talking abou the View in Visual Studio which is called Solution Explorer.
You can select it in Visual Studio through the menu:
View
→
Solution Explorer
. It the screen that shows the projects in your solution and the files in your project. The you can find the 'Reference' folder.
Martijn Kok
20-Sep-12 5:45am
View
Maybe I was looking in the wrong direction. You could try to search Google for the error massage. For instance this result shows in a totally different way. Something about a protection against 'assumed' unsafe UNC paths.
http://stackoverflow.com/questions/2926378/custom-wpf-namespace-mappings-failing-in-visual-studio-2010
. In the question they talk about using drive mappings. I'm not sure if this could apply to the error you get.
Martijn Kok
20-Sep-12 4:09am
View
I have added an example to store to CSV. The retrievement code will follow shortly
Martijn Kok
19-Sep-12 6:51am
View
The first question is if the namespaces ABC.XXX.YYY.Silverlight.Controls and .LoginUI are in the same project file as your XAML or in another projectfile/DLL. If they are in the same project file as your XAML. Then the following text won't help and my solution won't solve the problem.
If they are in anonther project file/DLL, then you probably have a refence to it (In the solution explorer look in the folder 'Reference'). The name that shows in the 'Reference' folder is your assembly name. I guess you already have a reference. Otherwise right click on 'Reference' folder. Select 'Add reference...'. Go to the browse tab and browse to the which contains the namespace.
Normally the location of the assembly is not relevant. At least not in WPF. In WPF the DLL's are put in the same directory as your program. I'm not sure how this is in SilverLight, but if I read the documentation from microsoft in the link I provided, then it should not be necessary to include the path to the assembly (see the 2nd note in the 'Mapping to custom assemblies' link)
Hopefully this is of any use.
Martijn Kok
19-Sep-12 2:17am
View
Saving to Excel without a reference to Excel (or without Excel installed on the computer you want to install your software) is not possible. Maybe there are commercial products which can save to an excel sheet without Excel installed.
You can look at alternatives if you ask yourself why you want to use Excel. If the answer is "I need to store my playlist somewhere", then there are other solutions. You could store it to a CSV file (text file a seperation character) or a XML file you define. These are free and simple to use. Another alternative is looking at using a database. Databases have advantages, but you need a database some where. The installed applications need to connect to the database. When you have more data and more complex data, databases are a very good alternative.
Martijn Kok
18-Sep-12 9:31am
View
WPF is just great. Most important is that one has to search for the obvious solution first, before making it more complicated.
I was wondering if you will need the Command at all, if you have the IsChecked. Actually I didn't know the CheckBox had a Command (still learning myself) If you only need to react to the CheckBox being set or not, the IsChecked binding could be sufficient. An advantage of the command might be the CanExecute functionality.
Martijn Kok
18-Sep-12 8:07am
View
You're welcome
Martijn Kok
15-Sep-12 8:09am
View
I read the question, but I do agree with the others that there is not really a question. It is not clear what the problem is and what needs to be solved.
In general it is best to describe the problem and descibe what you have done yourself to solve it. Code examples and error message will make it a lot clearer.
If you are new to a problem you could try google. If you search "C# get filenames in folder" you will find code how to read files from a folder. Search an example which looks 'good' and try it. If you run into problems or it is not would you really want, you can search further or ask in codeproject. Give examples of your code, that will help. Like this question about the backgroundworker. That was a great help in solving the problem.
Martijn Kok
13-Sep-12 8:43am
View
These articles are really great. I have the original design pattern book, but making a translation from examples in LISP or other older languages to .NET was too much for me. The articles made it much easier to understand.
Martijn Kok
11-Sep-12 7:15am
View
The fist thing I thought about is that when you click the ListView it has focus. When you click the pause button the focus shifts to the Pause button. It is quite common that an unfocussed control has different colors that a focussed one.
You can test it by clicking an item in the ListView. Then press the Tab button. Probably the color changes. Can you test this?
Problem is that I don't know how to change the colors in WinForms. I do know how to in WPF.
Martijn Kok
11-Sep-12 5:23am
View
Are you using WPF? (Or WinForms)
Martijn Kok
11-Sep-12 3:13am
View
Great you solved it and managed to use it.
Regular expressions are a powerful tool. If you search google for 'regular expressions .net' you'll find some very useful resources, that will help you use the power of regular expressions.
I'm glad I could help.
Regards,
Martijn
Martijn Kok
11-Sep-12 3:09am
View
You're welcome.
Regards,
Martijn
Martijn Kok
10-Sep-12 11:42am
View
I'm getting a little lost myself now :) I can't fully get a picture of what you are trying to achieve.
Are you trying to do another search with the text dectections were: Or are you trying to report an output text with detections were: Monday 23?
Martijn Kok
10-Sep-12 11:34am
View
I introduced the variable 'text' to show as an example, you should replace it with the string that contains your text or use the function directly on your string.
Martijn Kok
10-Sep-12 9:28am
View
I just realised that I don't know which version of C# you are using. Tuples exist in C# 4.0 (and probably in 3.5). Let me know if you are using an older version of C# and can't use Tuples.
Martijn Kok
10-Sep-12 9:10am
View
Hi Vasanth,
I have made some changes in the solution code. When calling RunAsync you'll need to pass an extra parameter. Because you are already using the argument to pass count, I've used a Tuple<int, int=""> to pass on a second argument (the currently selected item).
In the loop the variable j is set to this currentSelected. A boolean flag is set to true to ensure that this only happens the first time the code is called.
I wasn't able to test the code. I don't hope I made typing errors. Let me know if you run into a problem.
Martijn Kok
10-Sep-12 5:31am
View
Regex does have a Replace method, how ever in this case it won't work as you need. A work around is getting the value of a Group and replace the original string with the value of this group. I have changed the solution to show this.
Martijn Kok
10-Sep-12 3:13am
View
You could have a look at this article. It explains regularexpressions: http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial
Regulare expressions can be complex and it's exact use depends on the text to search and your requirements. Studying it yourself might prove to be quite usefull in the future.
If you have any control over the way your 'Today Date: (...)' is formatted. I would say, that you might make sure that one is always the same format. But you probably haven't any influence on it.
The next question is: What does your result have to look like. Do you want a date value or do you want a text value containing: 'Monday 23', 'Monday23', 'Monday-23-2012', 'Monday.23-2012'.
If the latter is the case you could use the generic
Today Date\:? (.+),
(assuming you have a comma at the end of the line)
Martijn Kok
10-Sep-12 1:21am
View
I haven't enough information to know what is the bug. If the code is placed in a form called Form1, then it looks like the name of your form gets in the result. You'll need to debug your code. Place some breakpoints and try to find where the result changes into Form1.
Martijn Kok
10-Sep-12 1:15am
View
With regular expressions there are always to question you have to ask yourself:
1. What are the different variations of texts I have to search?
2. What should your result look like?
In this case. You want the output to be: Monday-23-2012 and Monday.23-2012 or just Monday 23?
Martijn Kok
10-Sep-12 1:12am
View
It will also detect every combination of 1 word and 1 numberic value
Martijn Kok
4-Sep-12 8:22am
View
I haven't look at it that way. Dynamic interception won't solve this. Hopefully someoneelse knows how to use DI in this case.
Martijn Kok
28-Aug-12 7:00am
View
You're right. I'm glad it worked.
Martijn Kok
23-Aug-12 4:26am
View
Hi Vasanth,
This is my last post on this item. I asked you twice to make a new question so that all the other experts could help also. As you state yourself that public post queries are no good. I wish to stick to the rules of codeproject. What I can do is watching out for questions you ask in the Quick Answers section. I'll help if I have the knowledge and time.
Concerning the problem at hand. I can give you a simple hint. Each item in the playlist has it's own time. Stored in de listView_palylist.SelectedItems[index].Tag. So when you need the time in the background worker get if from that tag instead off the txtbox_timertime.
int time = Convert.ToInt32(listview_playlist.Selecteditems[0].Tag.ToStrng());
And you should make listview_palylist.MultiSelect = false; This prevents the possibility that multiple items are selected.
I hope this is of use. If you have more questions ask a new question in the 'Quick Answers' section. So everyone can give it a try to solve.
Martijn Kok
22-Aug-12 15:12pm
View
I have 2 more questions after reading this explanation.
Concerning problem 1: how do you store time in the ListView. And how do you store the filename. Can you show me the part where you store the value of the txtbox_timertime.Text into the listview item (1 line should do). And also the code where you store the filename into the listview
Concerning problem 2) Can you verify what the value of the following property of the ListView is: MultiSelect. I would guess it is true?
Martijn Kok
22-Aug-12 9:30am
View
I do have some additional questions to understand your question.
1) What are you showing in the listview? Titles of songs?
2) What kind of class is put in the items of the Listview? Only strings with the titles of songs or something else like a class or a structure
3) if is is a class or a structur (or something like a DataRow) which fields are there in that class
4) I assume you only has 1 txtbox_timertime on your form?
5) How are the values in this txtbox_timertime.Text changed. By code or do you need to input the time.
You really might want to post your question as a new question. I will try help you on this one, but actually you are asking a new question. Your first question was for the most part about the BackgroundWorker, and this new question is more about a ListView. Until 5 days ago I have never looked at a ListView. If have used ListBox and I think that I know what the problem is, but I'm not as sure as with the BackgroundWorker question. Other developers might have a lot more experience with the ListView.
I'll study the ListView a little more. Maybe I'll find something to help you.
Martijn Kok
22-Aug-12 5:32am
View
Hi Vasanth,
I'll look into it in about a few hours (currently working). You should also try to make this a new question. This will give other experts a chance to look at the problem too. All the experts together will definitly know more than I alone, and they will see the new question, but I doubt they will see this comment.
My first approach to this new problem would be to check which value is actually in the time int. Either place a breakpoint or insert a Console.WriteLine(time.ToString()); after the 'int time = ...' line. Check the output view of Visual Studio. Does it show 25 seconds or 2 seconds.
I would expect 2 seconds. So the problem is not the thread by the value in txtbox_timertime.Text.
Martijn Kok
21-Aug-12 8:59am
View
The values are shown like dates around january 1st 1900 because the value is interpreted as a DateTime. You have specified only a time. Because the datetime field needs a date too, the date 0 is added. With the DateTime class this is december 31th 1899. So 0:00:28 is translated into 12\31\1899 0:00:28.
Martijn Kok
21-Aug-12 8:52am
View
If you are interested in a book about LINQ you might try: http://www.apress.com/9781430226536 This book learned me much about LINQ. The first part is about LINQ in general (including grouping) and LINQ to XML, LINQ to DataSet and LINQ to Entity are also discussed. But there are probably other good books about LINQ.
It would be great if you can share your own knowledge about LINQ in the future with others.
Martijn Kok
21-Aug-12 7:42am
View
Aparently there is a non-valid cast. And there might be 2 candidates for it. First the TotalSeconds (which is a double) to an int. This might be solved with
avg = new TimeSpan(0, 0, (int)(grp.Average(r => r.Field("id").TimeOfDay.TotalSeconds))),
And secondly, which probably is the case, the value in the ID field might be a datetime. You could try this
avg = new TimeSpan(0, 0, (int)grp.Average(r => r.Field<DateTime>("id").TimeOfDay.TotalSeconds)),
If this doesn't help. There might be another problem, namelijk that the value in the Field("id") in not the DateTime. I assumed it was a value like: 00:00:28 but this might not be the case.
Place a Console.WriteLine(dtTbl.Rows[0].Field("id")); in your code a have a look what the output is.
For LINQ you can have a look at this site: http://msdn.microsoft.com/en-us/vstudio//aa336746
Martijn Kok
20-Aug-12 8:39am
View
You're welcome
Martijn Kok
20-Aug-12 2:25am
View
I have some assumptions to make because you don't supply much information about the error.
Is this VB from an Access application? I have seen this error there indicating that RTrim is an unknown function. If that is the case you might miss a reference to a DLL. Menu Extra -> Reference. In the list of references you might see a missing reference. Remove the refence an recreate it.
Not sure if this error might occure in Visual Basic 6.
Martijn Kok
19-Aug-12 10:26am
View
If you look into the Visual Studio help for the BackgroundWorker.ReportProgress (or goto http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.reportprogress.aspx) you will see that there are two versions of the ReportProgress method.
You can use them based on the parameters you will supply. In your code you are using them both. If you only supply 1 parameter as an int (like in backgroundWorker1.ReportProgress(i * 100 / count)) then you are using the ReportProgress(int). If you read the help documentation you will see this one only can be used to report te progress.
When you supply 2 parameters (of which the first must be an int and the second can be any kind of object) you will use the ReportProgress(int,object). In the code this is the backgroundWorker1.ReportProgress(i * 100 / count, j). In this example the 2nd parameter is also an int, but it could be anything. In the helpdocumentation you will see that this parameter represents the UserState.
Having 2 or more signatures of the same method is called method overloading. You can use it in your own code too. For instance look at this page http://csharp.net-tutorials.com/classes/method-overloading/
Martijn Kok
14-Aug-12 8:13am
View
In general you need to go through 3 steps:
1. Get a reference to the RegionManager
2. Get the Region with the 3 views
3. Get the view and enable/show the wanted view and disble/hide the others
On which step do you need help? If you need help on getting the RegionManager I have an additional question. Are you using Unity and a UnityBootstrapper?
Martijn Kok
1-Aug-12 7:14am
View
You are right. Thanks. The example data only contains Leaves on May001. Joining on Leave and EmpCode is more generic.
*Martijn goes back to the SQL 101 class* :)
Martijn Kok
1-Aug-12 7:02am
View
I wouldn't have thought about the XML PATH to solve this problem. After seeing your solution I have been trying some.
If you replace T2.Leave=T1.Leave with T2.EmpCode=T1.Empcode, the query will work.
Martijn Kok
26-Jul-12 2:27am
View
You're welcome. Good job solving it yourself
Martijn Kok
25-Jul-12 0:54am
View
When txtid.Text contains the condition you need to retrieve the right Prcshool record, this would be the way to fill your resulting Me.DataSet2.prcschool table.
Do you get an error or something?
Show More