Click here to Skip to main content
15,917,652 members
Home / Discussions / C#
   

C#

 
GeneralRe: Validate model on initial request Pin
BobJanova31-Mar-14 0:48
BobJanova31-Mar-14 0:48 
GeneralRe: Validate model on initial request Pin
Pete O'Hanlon31-Mar-14 1:21
mvePete O'Hanlon31-Mar-14 1:21 
GeneralRe: Validate model on initial request Pin
BobJanova31-Mar-14 2:18
BobJanova31-Mar-14 2:18 
AnswerRe: Validate model on initial request Pin
Dave Kreskowiak31-Mar-14 2:14
mveDave Kreskowiak31-Mar-14 2:14 
QuestionRouting event to particular control Pin
samaruf28-Mar-14 16:24
samaruf28-Mar-14 16:24 
QuestionTiff Image Copied with extra bytes Pin
cravi8528-Mar-14 10:50
cravi8528-Mar-14 10:50 
AnswerRe: Tiff Image Copied with extra bytes Pin
Ravi Bhavnani28-Mar-14 11:00
professionalRavi Bhavnani28-Mar-14 11:00 
GeneralRe: Tiff Image Copied with extra bytes Pin
cravi8528-Mar-14 18:26
cravi8528-Mar-14 18:26 
This is the code file. I added onlymain thing. Other manipulations are confidential. So i am sorry for not able to give full code. But this part only related to file operation.

Major methods are ,

File.move , File.Copy.
This is Parellal Process. So i am using Parellal method.

The source code as below


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

namespace AccessSharedFiles
{
public partial class Parellal : Form
{
public Queue queBatch;

public System.Timers.Timer DurationForCopy;
public System.Timers.Timer DurationForProcess;
public bool currentlyProcessing = true;
public bool currentlyCopying = true;
public Parellal()
{
InitializeComponent();
}

private void Parellal_Load(object sender, EventArgs e)
{
try
{
queBatch = new Queue();
DurationForCopy = new System.Timers.Timer();
DurationForCopy.Interval = 5 * 1000;
DurationForCopy.Enabled = true;
DurationForCopy.Elapsed += new ElapsedEventHandler(CopyFiles);

DurationForProcess = new System.Timers.Timer();
DurationForProcess.Interval = 5 * 1000;
DurationForProcess.Enabled = true;
DurationForProcess.Elapsed += new ElapsedEventHandler(ProcessFiles);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}

private void CopyFiles(object sender, EventArgs eArgs)
{
try
{
if (currentlyCopying)
{
currentlyCopying = false;
string[] files = Directory.GetFiles( @"C:\SDU\SDU_Parel\Source\");
foreach (string fi in files)
{
File.Move(fi, @"C:\SDU\SDU_Parel\Intermediate\" + fi.Split('\\')[fi.Split('\\').Length - 1].Split('.')[0] + ".tif");
PutFolderinQueue(fi.Split('\\')[fi.Split('\\').Length - 1].Split('.')[0] + ".tif");
break;
}
}
currentlyCopying = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
currentlyCopying = true;
}
}

private void PutFolderinQueue(string fileName)
{
try
{
string strVal = fileName.ToString();
Monitor.Enter(queBatch);
queBatch.Enqueue(fileName);
Monitor.Exit(queBatch);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void ProcessFiles(object sender, EventArgs eArgs)
{
try
{
if (currentlyProcessing)
{
currentlyProcessing = false;
List<string> al = new List<string>();
Monitor.Enter(queBatch);
if (queBatch.Count > 0)
{
for (int intCount = 1; intCount <= queBatch.Count; intCount++)
al.Add(queBatch.Dequeue().ToString().Trim());
}
Monitor.Exit(queBatch);
Parallel.ForEach(al, name => { ProcessBatch(name); });
if (al != null)
{
al = null;
}
currentlyProcessing = true;
GC.Collect();
}
}
catch (Exception ex)
{
currentlyProcessing = true;
MessageBox.Show(ex.Message);
}
}
private void ProcessBatch(string ivalue)
{
try
{
File.Copy(@"C:\SDU\SDU_Parel\Intermediate\"+ivalue, @"C:\SDU\SDU_Parel\Destination\" + ivalue);
File.Delete(@"C:\SDU\SDU_Parel\Intermediate\" + ivalue);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
GeneralRe: Tiff Image Copied with extra bytes Pin
cravi8528-Mar-14 18:38
cravi8528-Mar-14 18:38 
GeneralRe: Tiff Image Copied with extra bytes Pin
Ravi Bhavnani29-Mar-14 4:37
professionalRavi Bhavnani29-Mar-14 4:37 
GeneralRe: Tiff Image Copied with extra bytes Pin
BobJanova31-Mar-14 0:35
BobJanova31-Mar-14 0:35 
GeneralRe: Tiff Image Copied with extra bytes Pin
cravi8531-Mar-14 17:21
cravi8531-Mar-14 17:21 
AnswerRe: Tiff Image Copied with extra bytes Pin
Dave Kreskowiak28-Mar-14 13:02
mveDave Kreskowiak28-Mar-14 13:02 
GeneralRe: Tiff Image Copied with extra bytes Pin
cravi8528-Mar-14 18:39
cravi8528-Mar-14 18:39 
GeneralRe: Tiff Image Copied with extra bytes Pin
Dave Kreskowiak29-Mar-14 3:29
mveDave Kreskowiak29-Mar-14 3:29 
GeneralRe: Tiff Image Copied with extra bytes Pin
cravi8529-Mar-14 3:39
cravi8529-Mar-14 3:39 
GeneralRe: Tiff Image Copied with extra bytes Pin
Dave Kreskowiak29-Mar-14 3:59
mveDave Kreskowiak29-Mar-14 3:59 
GeneralRe: Tiff Image Copied with extra bytes Pin
cravi8529-Mar-14 5:01
cravi8529-Mar-14 5:01 
GeneralRe: Tiff Image Copied with extra bytes Pin
Dave Kreskowiak29-Mar-14 19:53
mveDave Kreskowiak29-Mar-14 19:53 
QuestionC# Pin
Member 1068292828-Mar-14 7:42
Member 1068292828-Mar-14 7:42 
AnswerRe: C# Pin
Richard MacCutchan28-Mar-14 8:07
mveRichard MacCutchan28-Mar-14 8:07 
AnswerRe: C# Pin
PIEBALDconsult28-Mar-14 8:19
mvePIEBALDconsult28-Mar-14 8:19 
GeneralRe: C# Pin
thatraja30-Mar-14 23:34
professionalthatraja30-Mar-14 23:34 
AnswerRe: C# Pin
Dave Kreskowiak28-Mar-14 9:38
mveDave Kreskowiak28-Mar-14 9:38 
GeneralRe: C# Pin
PIEBALDconsult31-Mar-14 3:48
mvePIEBALDconsult31-Mar-14 3:48 

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.