|
Unfortunately that is the nature of code bugs, they only happen when you least expect them. The only way to track the problem is by debugging and testing. You should examine all the information in the exception including the stack trace, in order to try and find out what has happened leading up to the error.
|
|
|
|
|
Good day.
Please fix the formatting. It makes it really hard to read, so I have not read through your code.
Anyway, the first thing that comes to mind is check that when you try to navigate to a XAML page a second time, the
NavigationService.Navigate method already has the page you are trying to navigate to in memory.
Something similar happened to me quote some time ago.
I fixed it by first checking if the page I wanted to navigate to was not already loaded into the NavigationService. If it was, I didn't do anything, else let the Navigation proceed.
Hope that helps.
Neill
|
|
|
|
|
How do I check if the page is already loaded or not in WPF?
|
|
|
|
|
Its been a while but a quick search leads me to using CurrentSource of the NavigationService.
Something like:
NavigationWindow.CurrentSource.ToString());
|
|
|
|
|
Currentsource property not available
|
|
|
|
|
Like I said, its only a possibility that that is causing your problem.
Do some research to try and figure out how to get the CurrentSource, we can't do everything for you.
Neill
|
|
|
|
|
It means you don't have any clue to suggest. Thanks anyways.
|
|
|
|
|
After reviewing some more, it is quite likely that the code is losing reference to the NavigationService object due to DoTrans() being run on a different thread.
But hey, maybe I just don't have any clue to suggest.
Good luck in finding the problem.
Neill
|
|
|
|
|
I have the following code To get the prime numbers between a range of numbers, is this the best and fast method?
int[] NumberCollection = Enumerable.Range(startNum,Count).ToArray<int>();
string primeNumbers = string.Join(",", from number in NumberCollection
where (IsPrime(number)==true)
select number);
Where :
startNum is the starting number
Count is the number of numbers in the collection
IsPrimeis defined as follows:
private static bool IsPrime(int number)
{
for (int i = 2; i < number; i++)
if (number % i == 0) return false;
return true;
}
sujith karivelil
Microsoft Technology Associate
|
|
|
|
|
No.
For starters, your loop is going to check each and every possible divisor from 2 on up: so if the number is 13, it will check 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12.
Since you checked 2 to start with, it can't be divisible by any other even number - so why check them?
Then you would check 2, 3, 5, 7, 9, 11
But...since it's not divisible by 2, it isn't divisible by any number greater than number / 2 so why check 7, 9, 11?
Two simple changes, and you reduce the number of loops from 12, to 3...
I'd suggest that you tart by doing some reading: https://en.wikipedia.org/wiki/Primality_test[^] - there are much more efficient methods.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ya, that's fine and good suggestion
sujith karivelil
|
|
|
|
|
In an existing C# desktop 2010 application, I need to have two or more users share the same computer. The users will run the same desktop application but have access to different files and folders on the network share. Each person will have their own unqiue config file to show what files they have access to. Each person has their own Access 2013 database files. That is one of the files the users have access to.
Based upon what I have said, I have the following questions to ask:
1. Will I need separate installs of the application on the same computer? Part of the install process includes placing the app.config file in the correct location. If so, can you tell me what I need to do for the separate installs?
2. If I do not need separate installs, what should I do about the separate app.config files? Each person's config file will point to files they directly have access to. I do not want each person to access the other person's config file.
|
|
|
|
|
1. No, you should only need one install of the application. However each user will need their own app.config file so the application knows which files to access.
2. See 1. Alternatively you could put information in the app.config file to identify which files/directories to associate with which user.
|
|
|
|
|
|
class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
var v = File.ReadLines("dictionary.txt");
var v1 = args[2];
var v2 = args[3];
var first = v.Where(w => w == v1).First();
var last = v.Where(w => w == v2).First();
var l = Array.IndexOf(v.ToArray(), first);
var l2 = Array.IndexOf(v.ToArray(), last);
var l3 = l2 - l;
var results = v.Skip(l).Take(l3);
foreach (var result in results)
{
Console.WriteLine(result);
}
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("Arguments invalid");
}
}
}
|
|
|
|
|
Member 12055749 wrote: Bugging me on a forum.
Member 12055749 wrote: It is bad.
Member 12055749 wrote: how could you improve this implementation? Verify if there's a third argument on the commandline before accessing it, replace the "var" declarations with something descriptive, and add exception handling and logging. I would also check the validity of the arguments at the start, and throw an exception if they are invalid, as opposed to using an else statement. And get rid of variable names like "v1".
Member 12055749 wrote: Using a unit-test?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's not all bad.
I was looking at it thinking, surely that should be File.ReadAllLines, but in fact no, File.ReadLines is there too. Didn't know that and now I know the subtle difference.
Something new, every day.
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: It's not all bad. That's true; it is indented correctly
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
1.
V = Extract dictionary.txt file content to a string
V1 = Contains string[] 3rd element
V2 = Contains string[] 4th element
First = Extract from V the first string matching with V1
Last = Extract from V the first string matching with V2
l = Get from V the index of First
l2 = Get from V the index of Last
l3 = Length of Last - First
Results = Skip first element and return next l3 elements
Print Results
The code is reading dictionary.txt and print all results between index of 3rd and 4th array element.
2. This code is hard to read. Variable names aren't intuitive. Doesn't seem to be necessary use var because some types aren't anonymous. ReadLines return a string[], V1 and V2 are strings, l, l2 and l3 are integer.
|
|
|
|
|
Of course, the easy way for you to answer the questions would be to actually run the program and step through it. You'll be amazed at what you can learn.
|
|
|
|
|
This smells like homework. What do you think it does? What do you think of the code quality?
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
especially if you look at the poster's profile
Best,
John
|
|
|
|
|
i'm a newbie in IT and i'm learning C program.i'm wrote this code and it has error message.
-------
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i;
long s;
scanf ("%d" ,&n);
s=0;
i=1;
while (i<=n)
{
s=s+i;
i=i+1;
}
printf("%ld",s);
}
modified 13-Oct-15 11:37am.
|
|
|
|
|
What is the error message you are getting? Also, in future posts, use a more descriptive subject line, and place in the correct forum since you have a C program problem and this is the C# forum.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
I just built and ran your code and there are no error messages. There is one warning about using scanf_s instead of scanf , but that can be safely ignored for now.
I suggest you post the full details in the C forum, making sure you include the exact text of the error message.
|
|
|
|