Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: error ExecuteReader() Pin
Member 107105323-Apr-15 2:00
Member 107105323-Apr-15 2:00 
SuggestionRe: error ExecuteReader() Pin
Richard Deeming7-Apr-15 2:37
mveRichard Deeming7-Apr-15 2:37 
QuestionMerge with uEye cam capture program c# with c# socket programming (Server Only) Pin
Member 115345522-Apr-15 22:35
Member 115345522-Apr-15 22:35 
AnswerRe: Merge with uEye cam capture program c# with c# socket programming (Server Only) Pin
OriginalGriff2-Apr-15 22:41
mveOriginalGriff2-Apr-15 22:41 
GeneralRe: Merge with uEye cam capture program c# with c# socket programming (Server Only) Pin
Member 115345522-Apr-15 23:20
Member 115345522-Apr-15 23:20 
GeneralRe: Merge with uEye cam capture program c# with c# socket programming (Server Only) Pin
OriginalGriff2-Apr-15 23:23
mveOriginalGriff2-Apr-15 23:23 
QuestionRe: Merge with uEye cam capture program c# with c# socket programming (Server Only) Pin
Eddy Vluggen3-Apr-15 1:13
professionalEddy Vluggen3-Apr-15 1:13 
QuestionI have a cool program if anyone would like to take it on. Pin
Dr Gadgit2-Apr-15 11:02
Dr Gadgit2-Apr-15 11:02 
AnswerRe: I have a cool program if anyone would like to take it on. Pin
OriginalGriff2-Apr-15 21:37
mveOriginalGriff2-Apr-15 21:37 
AnswerRe: I have a cool program if anyone would like to take it on. Pin
Eddy Vluggen4-Apr-15 2:34
professionalEddy Vluggen4-Apr-15 2:34 
QuestionMySQL Data Synchronisation between Databases in C# Pin
RevathySanthanam2-Apr-15 4:14
RevathySanthanam2-Apr-15 4:14 
Rant[REPOST] MySQL Data Synchronisation between Databases in C# Pin
Richard Deeming2-Apr-15 4:42
mveRichard Deeming2-Apr-15 4:42 
QuestionTime out handling in System.Threading.Task class in dotnet 4.0 Pin
Member 113878772-Apr-15 0:11
Member 113878772-Apr-15 0:11 
AnswerRe: Time out handling in System.Threading.Task class in dotnet 4.0 Pin
Pete O'Hanlon2-Apr-15 0:47
mvePete O'Hanlon2-Apr-15 0:47 
AnswerRe: Time out handling in System.Threading.Task class in dotnet 4.0 Pin
Afzaal Ahmad Zeeshan2-Apr-15 1:04
professionalAfzaal Ahmad Zeeshan2-Apr-15 1:04 
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 

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.