1

このファンキーなエラーが発生します:

これは単純な C# プログラムで、ソースは次のとおりです。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Threading;
using System.IO;

namespace SpintaxDecoder
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<string> sentences = new List<string>();
        public int Count = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Generating...";
            button1.Enabled = false;

            Application.DoEvents();

            string data = richTextBox1.Text;

            Random rand = new Random(this.Timestamp());

            for (; ; )
            {
                string spun = this.spintax(rand, data);

                if (sentences.Contains(spun) != true)
                {
                    sentences.Add(spun);
                }
                else
                {
                    this.Count++;
                }

                if (this.Count == 1000)
                {
                    break;
                }

            }

            label2.Text = this.sentences.Count().ToString();

            foreach (string sentence in sentences)
            {
                richTextBox2.Text += sentence + "\n";
            }

            MessageBox.Show("Completed!", "Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);

            button1.Enabled = true;
            button1.Text = "Start Decoding";

            this.sentences.Clear();
            this.Count = 0;
        }

        public int Timestamp()
        {
            long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
            ticks /= 10000000;
            return Convert.ToInt32(ticks);
        }

        public string spintax(Random rnd, string str)
        {
            string pattern = "{[^{}]*}";
            Match m = Regex.Match(str, pattern);
            while (m.Success)
            {
                string seg = str.Substring(m.Index + 1, m.Length - 2);
                string[] choices = seg.Split('|');
                str = str.Substring(0, m.Index) + choices[rnd.Next(choices.Length)] + str.Substring(m.Index + m.Length);
                m = Regex.Match(str, pattern);
            }

            return str;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "Text File|.txt";
            saveFileDialog1.InitialDirectory = "C:\\";
            saveFileDialog1.ShowDialog();

            string file = saveFileDialog1.FileName;

            if (file.Trim() != "")
            {
                StreamWriter writer = new StreamWriter(file);

                string[] lines = richTextBox2.Text.Split('\n');

                foreach(string line in lines)
                {
                    writer.WriteLine(line);
                }

                writer.Close();
                MessageBox.Show("File saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}

http://pastebin.com/hUjmAvhe

このエラーがどのように発生したかわかりません。以前はうまく機能していましたが、今はそれを開いたところ、このエラーが発生しました。

4

1 に答える 1