Click here to Skip to main content
15,883,829 members
Home / Discussions / C#
   

C#

 
QuestionLinq extension method and referencing object? Pin
TMattC1-Apr-15 22:24
TMattC1-Apr-15 22:24 
AnswerRe: Linq extension method and referencing object? Pin
OriginalGriff1-Apr-15 23:47
mveOriginalGriff1-Apr-15 23:47 
GeneralRe: Linq extension method and referencing object? Pin
TMattC2-Apr-15 3:49
TMattC2-Apr-15 3:49 
GeneralRe: Linq extension method and referencing object? Pin
OriginalGriff2-Apr-15 4:05
mveOriginalGriff2-Apr-15 4:05 
GeneralRe: Linq extension method and referencing object? Pin
TMattC2-Apr-15 5:23
TMattC2-Apr-15 5:23 
GeneralRe: Linq extension method and referencing object? Pin
OriginalGriff2-Apr-15 5:47
mveOriginalGriff2-Apr-15 5:47 
GeneralRe: Linq extension method and referencing object? Pin
Simon_Whale2-Apr-15 4:12
Simon_Whale2-Apr-15 4:12 
Questionc# file I/O looking strange in task manager Pin
Dan Wulff1-Apr-15 11:16
Dan Wulff1-Apr-15 11:16 
Hi!

I have made a c# program that writes a binary file of approximately 16 MB, then proceeds to process the file by reading and writing individual bytes after specific rules.

Generating the inital file runs without any issues, but when the actual processing starts, so do my problems:

Test application:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            FileStream Stream = new FileStream("test.file", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            int i;
            int NumReads, NumWrites;
            NumReads = 0;
            NumWrites = 0;
            for (i = 0; i < 1024 * 1024; i++)
            {
                Stream.WriteByte(0);
                NumWrites++;
            }
            while (true)
            {
                for (i = 0; i < Stream.Length; i++)
                {
                    Stream.Position = i;
                    int x=Stream.ReadByte();
                    NumReads++;
                    if (i % 16 == 0)
                    {
                        Stream.Position = i + 8;
                        int y = Stream.ReadByte();
                        NumReads++; 
                        Stream.Position = i + 10;
                        Stream.WriteByte(1);
                        NumWrites++;
                    }
                }
                Console.WriteLine("Loop done. Reads="+NumReads.ToString()+", Writes="+NumWrites.ToString());
                ConsoleKeyInfo result = Console.ReadKey();
                if (result.Key==ConsoleKey.Escape) break;
            }
            Stream.Close();
        }
    }
}
The process is painfully slow, and the program appears to be reading huge amounts of data during the process, according to Task Manager, during program execution, it looks like the program is reading 300 MB/second, or more, which is about what my HDD can do. The number of writes performed are looking normal.

I have tried implementing counters for read and write operations, and these seem to match what I am trying to do.
I have tried lots of different buffer sizes when initializing the FileStream, but the results are the same.

I dont know whether it is Task Manager being off, or c# actually messing up I/O so badly.

Does anybody have any idea what is going on ?

Thanks in advance,

Dan

modified 2-Apr-15 1:15am.

SuggestionRe: c# file I/O looking strange in task manager Pin
Richard Deeming1-Apr-15 11:22
mveRichard Deeming1-Apr-15 11:22 
GeneralRe: c# file I/O looking strange in task manager Pin
Dan Wulff1-Apr-15 11:46
Dan Wulff1-Apr-15 11:46 
AnswerRe: c# file I/O looking strange in task manager Pin
Brisingr Aerowing1-Apr-15 11:23
professionalBrisingr Aerowing1-Apr-15 11:23 
GeneralRe: c# file I/O looking strange in task manager Pin
Dan Wulff1-Apr-15 11:44
Dan Wulff1-Apr-15 11:44 
AnswerRe: c# file I/O looking strange in task manager PinPopular
Richard MacCutchan1-Apr-15 21:15
mveRichard MacCutchan1-Apr-15 21:15 
GeneralRe: c# file I/O looking strange in task manager Pin
Dan Wulff2-Apr-15 10:31
Dan Wulff2-Apr-15 10:31 
AnswerRe: c# file I/O looking strange in task manager Pin
Gerry Schmitz1-Apr-15 21:31
mveGerry Schmitz1-Apr-15 21:31 
GeneralRe: c# file I/O looking strange in task manager Pin
Dan Wulff2-Apr-15 10:34
Dan Wulff2-Apr-15 10:34 
QuestionCreate a Developper Pin
Member 83675021-Apr-15 10:42
Member 83675021-Apr-15 10:42 
AnswerRe: Create a Developper Pin
Dave Kreskowiak1-Apr-15 10:57
mveDave Kreskowiak1-Apr-15 10:57 
GeneralRe: Create a Developper Pin
Member 83675021-Apr-15 11:26
Member 83675021-Apr-15 11:26 
GeneralRe: Create a Developper Pin
PIEBALDconsult1-Apr-15 11:00
mvePIEBALDconsult1-Apr-15 11:00 
QuestionImplementing signalR Asynchronous calls for web service calls with 2 minutes timeout Pin
Member 105259811-Apr-15 8:29
professionalMember 105259811-Apr-15 8:29 
AnswerRe: Implementing signalR Asynchronous calls for web service calls with 2 minutes timeout Pin
Pete O'Hanlon1-Apr-15 9:43
mvePete O'Hanlon1-Apr-15 9:43 
QuestionWindows 7 C# and biometric API Pin
jerome.dimitri.fortias@gmail.com1-Apr-15 2:57
jerome.dimitri.fortias@gmail.com1-Apr-15 2:57 
AnswerRe: Windows 7 C# and biometric API Pin
Pete O'Hanlon1-Apr-15 3:34
mvePete O'Hanlon1-Apr-15 3:34 
GeneralRe: Windows 7 C# and biometric API Pin
jerome.dimitri.fortias@gmail.com1-Apr-15 3:42
jerome.dimitri.fortias@gmail.com1-Apr-15 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.