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 8030039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:38:06+00:00 2026-06-05T00:38:06+00:00

i am very new to C#, and this is my first question, please be

  • 0

i am very new to C#, and this is my first question, please be gentle on me

I am trying to write a application to capture some tick data from the data provider, below is the main part of the program

void zf_TickEvent(object sender, ZenFire.TickEventArgs e)
{

    output myoutput = new output();

    myoutput.time = e.TimeStamp;
    myoutput.product = e.Product.ToString();
    myoutput.type = Enum.GetName(typeof(ZenFire.TickType), e.Type);
    myoutput.price = e.Price;
    myoutput.volume = e.Volume;

    using (StreamWriter writer = File.AppendText("c:\\log222.txt"))
    {

        writer.Write(myoutput.time.ToString(timeFmt) + ",");
        writer.Write(myoutput.product + "," );
        writer.Write(myoutput.type + "," );
        writer.Write(myoutput.price + ",");
        writer.Write(myoutput.volume + ",");

    }

i have successfully write the data into the text file, however i know that this method will be call like 10000 times a second during peak time, and open a file and append it many times a second is very inefficient, i was pointed to use a buffer or some sort, but i have no idea how to do it, i try reading the document but i still dont understand, thats why i turn in here for help.

Please give me some (working) snippet code so i can pointed to the write direction. thanks

EDIT: i have simplified the code as much as possible

    using (StreamWriter streamWriter = File.AppendText("c:\\output.txt"))
    {
        streamWriter.WriteLine(string.Format("{0},{1},{2},{3},{4}",
                        e.TimeStamp.ToString(timeFmt),
                        e.Product.ToString(),
                        Enum.GetName(typeof(ZenFire.TickType), e.Type),
                        e.Price,
                        e.Volume));
    }

ED has told me to make my stream to a field, how is the syntax looks like? can anyone post some code to help me? thanks a lot

  • 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-06-05T00:38:09+00:00Added an answer on June 5, 2026 at 12:38 am

    I would use String.Format:

    using (StreamWriter writer = new StreamWriter(@"c:\log222.txt", true))
            {
                writer.AutoFlush = true;
                writer.Write(String.Format("{0},{1},{2},{3},{4},", myoutput.time.ToString(timeFmt), 
                    myoutput.product, myoutput.type, myoutput.price, myoutput.volume);
            }
    

    If you use @ before string you don’t have to use double \.

    This is much faster – you write only once to the file instead of 5 times. Additionally you don’t use + operator with strings which is not the fastest operation 😉

    Also – if this is multithreading application – you should consider using some lock. It would prevent application from trying to write to the file from eg. 2 threads at one time.

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

Sidebar

Related Questions

I am very new to programming, so please forgive me if this question seems
Hi i am very new to java and this is my first piece of
I'm very new to trigger function. Actually this is the first time I'm using
Hiya I am very new to C#, infact this is basically my first task
I'm very new at this, but I need to create new tables from existing
I am all very new to this and am trying to use extended hex
I know this is a very simple question for you experts,but please forgive me.Im
This is my first post on here and I'm very new to iPhone developing,
First off, please accept my apologies if this question is basic, I mainly have
First, I am super-new to Objective-C/iOS development and, in fact, this question is for

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.