Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1082197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:15:58+00:00 2026-05-16T22:15:58+00:00

I have a WPF program built in C#, and part of it’s function is

  • 0

I have a WPF program built in C#, and part of it’s function is populating two ListBox controls. At the Window_Loaded event the program calls the Update() function in order to populate the ListBoxes, but it only executes part of the function. And if I call the function after an append has been made to the file, the function will even crash. The file is structured as follows :

content_for_first_listbox
content_for_second_listbox

The function Update is as follows :

private void UpdateURL()
{
    StreamReader rdr = new StreamReader("Links.db");
    string line;
    int dummy;
    URL.Clear();
    TAGS.Clear();
    while ((line = rdr.ReadLine()) != null)
    {
        dummy = line.IndexOf(' ');
        URL.Add(line.Substring(0, dummy));
        TAGS.Add(line.Substring(dummy + 1));
    }
    rdr.Close();
    LLinks.Items.Clear();
    LTags.Items.Clear();
    for (int a = 0; a < URL.Count; a++)
    {
        LLinks.Items.Add(new ListBoxItem().Content = URL[a]);
        LTags.Items.Add(new ListBoxItem().Content = TAGS[a]);
    }
}

It stops executing after the first loop, I found that out from debugging. And here is the append function

private void LBookmarkBT_Click(object sender, RoutedEventArgs e)
{
    StreamWriter wrt = new StreamWriter("Links.db", true);
    wrt.Write("\n" + LURLTBox.Text + " " + LTagsTBox.Text);
    wrt.Close();
    UpdateURL();
}

Any ideas ?

Update : The problem is that it was reading the all the lines and parsed them correctly but then it would read a newline out of nowhere, the line string became “” and therefore dummy = -1 and it threw a length exception. I managed to overcome this by putting the loop in a try-catch block and discarding the exception, and everything works fine, but it seems kind of, “dirty” if I may say so. What should I do ? Perhaps and if(dummy == -1) don’t parse the line ?

        try
        {
            while ((line = rdr.ReadLine()) != null)
            {
                dummy = line.IndexOf(' ');
                URL.Add(line.Substring(0, dummy));
                TAGS.Add(line.Substring(dummy + 1));
            }
        }
        catch (Exception e)
        { }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:15:59+00:00Added an answer on May 16, 2026 at 10:15 pm

    Try running with “Break when an exception is thrown” enabled in the Exceptions dialog (Ctrl+Alt+E in VS.Net / Debug\Exceptions… menu option). This should break the debugger when an exception is thrown – which is almost certainly what you’re getting here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a series of event handlers for some custom WPF controls. The
I have a WPF program with two listviews which display information from two different
Here you have a simple WPF program: <!-- Updater.xaml --> <Window x:Class=Update.Updater xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have a general purpose Utility dll file used in my WPF program. The
I have a c# program using WPF. I have it that when you press
I have a program running under WPF and MVVM. I have some daily worked
I have WPF Application where I have One main form and other user controls
I have a WPF application, where as part of the startup, I need to
Say, I have a WPF program with a Windows Forms control in WindowsFormsHost on
I am writing a WPF program in C# in which I have a ListView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.