Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CSV file based on timer event

CSV file based on timer event

Scheduled Pinned Locked Moved C#
csharpquestion
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mprice214

    This works, but it seems a bit flakey. Also, does anyone know how to limit the file size?

    using (StreamWriter writer = new StreamWriter("C:\\log.csv", true)) //add ,true to this to append
    {
    writer.WriteLine(textBox1.Text + "," + System.DateTime.Now);

            }
    
    R Offline
    R Offline
    Ravi Bhavnani
    wrote on last edited by
    #7

    mprice214 wrote:

    This works, but it seems a bit flakey.

    Define "flakey". Remember, a Timer is only one way to go. You could also use a background thread. In this case, be sure to handle concurrent access of UI (and other) data. /ravi

    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

    L 1 Reply Last reply
    0
    • R Ravi Bhavnani

      mprice214 wrote:

      This works, but it seems a bit flakey.

      Define "flakey". Remember, a Timer is only one way to go. You could also use a background thread. In this case, be sure to handle concurrent access of UI (and other) data. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #8

      No problem[^]. :-D

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Prolific encyclopedia fixture proof-reader browser patron addict?
      We all depend on the beast below.


      M R 2 Replies Last reply
      0
      • L Luc Pattyn

        No problem[^]. :-D

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        M Offline
        M Offline
        mprice214
        wrote on last edited by
        #9

        Luc Pattyn wrote:

        No problem[^].

        Come again?

        R 1 Reply Last reply
        0
        • L Luc Pattyn

          No problem[^]. :-D

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #10

          :) OT: I wished I lived in Belgium. It's a collector's haven for Dinky Toys. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          L 1 Reply Last reply
          0
          • M mprice214

            Luc Pattyn wrote:

            No problem[^].

            Come again?

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #11

            Luc is just having some fun at our expense. :) /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            1 Reply Last reply
            0
            • R Ravi Bhavnani

              :) OT: I wished I lived in Belgium. It's a collector's haven for Dinky Toys. /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #12

              Ravi Bhavnani wrote:

              collector's haven for Dinky Toys

              is it? I wasn't aware, I haven't seen one for ages. I am a model railroad enthusiast myself (N gauge, i.e. scale 1:160). :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              R 1 Reply Last reply
              0
              • L Luc Pattyn

                Ravi Bhavnani wrote:

                collector's haven for Dinky Toys

                is it? I wasn't aware, I haven't seen one for ages. I am a model railroad enthusiast myself (N gauge, i.e. scale 1:160). :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Prolific encyclopedia fixture proof-reader browser patron addict?
                We all depend on the beast below.


                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #13

                Luc Pattyn wrote:

                I haven't seen one for ages.

                You can relive some childhood memories here[^]. :) /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                L 1 Reply Last reply
                0
                • R Ravi Bhavnani

                  Luc Pattyn wrote:

                  I haven't seen one for ages.

                  You can relive some childhood memories here[^]. :) /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #14

                  Great. The very first image[^] I looked at has a bill board for a shop in Ghent that is still there; I have bought some locs there once. Normally I go shopping in Germany... :) PS: may I suggest you add some navigation to your catalogs, moving to the next/previous page would increase the "user experience".

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  Prolific encyclopedia fixture proof-reader browser patron addict?
                  We all depend on the beast below.


                  1 Reply Last reply
                  0
                  • M mprice214

                    Hi all, I've been looking for a way to write data to a CSV file based on a timer event, without success. Is there a standard .NET class that will do this? Thanks.

                    A Offline
                    A Offline
                    AspDotNetDev
                    wrote on last edited by
                    #15

                    Sounds like you are doing some profiling/tracing. Google those terms, perhaps in combination with "C#" and anything more specific you are interested in. Or do as others say and create a timer that appends to the CSV file.

                    [Forum Guidelines]

                    1 Reply Last reply
                    0
                    • M mprice214

                      Hi all, I've been looking for a way to write data to a CSV file based on a timer event, without success. Is there a standard .NET class that will do this? Thanks.

                      Y Offline
                      Y Offline
                      yu jian
                      wrote on last edited by
                      #16

                      Hi boy, try this. :)

                      using System;
                      using System.Windows.Forms;
                      using System.IO;
                      
                      namespace WriteCSV
                      {
                          public partial class Form1 : Form
                          {
                              public Form1()
                              {
                                  InitializeComponent();
                              }
                      
                              private void button1_Click(object sender, EventArgs e)
                              {
                                  this.timer1.Enabled = !this.timer1.Enabled;
                              }
                      
                              private void timer1_Tick(object sender, EventArgs e)
                              {
                                  FileStream fs = new FileStream("test.csv",  FileMode.Append, FileAccess.Write);
                                  StreamWriter sw = new StreamWriter(fs);
                                  sw.WriteLine(DateTime.Now.ToString());
                                  sw.Close();
                                  fs.Close();
                              }
                          }
                      }
                      
                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups