Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: Converting InAppBilling.Plugin to Amazon Pin
Kris Lantz2-Jun-20 9:13
professionalKris Lantz2-Jun-20 9:13 
GeneralRe: Converting InAppBilling.Plugin to Amazon Pin
Exoskeletor2-Jun-20 9:24
Exoskeletor2-Jun-20 9:24 
QuestionState machine performance woes in .NET Pin
kalberts2-Jun-20 3:04
kalberts2-Jun-20 3:04 
AnswerRe: State machine performance woes in .NET Pin
kalberts2-Jun-20 3:41
kalberts2-Jun-20 3:41 
GeneralRe: State machine performance woes in .NET Pin
F-ES Sitecore2-Jun-20 4:08
professionalF-ES Sitecore2-Jun-20 4:08 
QuestionProblem with Currency format Column Calculation in my dGV in C# Winform Application. Pin
Member 1467808531-May-20 6:47
Member 1467808531-May-20 6:47 
AnswerRe: Problem with Currency format Column Calculation in my dGV in C# Winform Application. Pin
OriginalGriff31-May-20 20:34
mveOriginalGriff31-May-20 20:34 
QuestionMulti threading in C# Pin
bjwaldo28-May-20 9:21
bjwaldo28-May-20 9:21 
I am attempting to learn programming in c# to begin with and have run into an issue I can't figure out yet. Am hoping fro some help, direction, etc. The code below works just fine when I don't use any multi threading but one I try to multi thread I am getting the following error: "Argument 1: cannot convert from 'void' to 'System.Threading.ThreadStart'" This error is shown on the line "var bkpthread = new Thread(CopyDirectory(source.ToString(), target.ToString()))"

Code:
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.IO;
using System.Text;
using System.Windows.Forms;
using MessageBox = System.Windows.Forms.MessageBox;
using System.Threading;

class Folders
{
#pragma warning disable IDE1006 // Naming Styles
    public string pth { get; set; }
}

namespace Backup_Tool
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            foreach (var Drives in Environment.GetLogicalDrives())
            {
                System.IO.DriveInfo DriveInf = new System.IO.DriveInfo(Drives);
                if (DriveInf.IsReady == true)
                {
                    ddlDrives.Items.Add(DriveInf.Name);
                }
            }
            ListView1.Items.Add(new Folders() { pth = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) });
            ListView1.Items.Add(new Folders() { pth = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) });
            ListView1.Items.Add(new Folders() { pth = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\" + "Downloads" });
            ListView1.Items.Add(new Folders() { pth = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) });
            ListView1.Items.Add(new Folders() { pth = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) });
            ListView1.Items.Add(new Folders() { pth = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos) });
        }

        public void ChkDest()
        {
            string message = "You must first select a destination";
            string title = "Destination Error";
            MessageBoxButtons buttons = MessageBoxButtons.OK;
            MessageBox.Show(message, title, buttons, MessageBoxIcon.Warning);
        }

        private void Cls_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Application.Current.Shutdown();
        }

        private void AddFolder_Click(object sender, RoutedEventArgs e)
        {
            var fbd = new FolderBrowserDialog { };
            if (fbd.ShowDialog().ToString().Equals("OK"))
                ListView1.Items.Add(new Folders() { pth = fbd.SelectedPath });
        }

        private void FullSystem_Click(object sender, RoutedEventArgs e)
        {
            ChkDest();
        }

        private void DelFolder_Click(object sender, RoutedEventArgs e)
        {
            ListView1.Items.RemoveAt(ListView1.SelectedIndex);
        }

        private void FldBackup_Click(object sender, RoutedEventArgs e)
        {
            if (ddlDrives.SelectedIndex > -1 && ddlDrives.SelectedItem != null && !string.IsNullOrEmpty(ddlDrives.SelectedItem.ToString()))
            {
                foreach (Folders item in ListView1.Items.Cast<folders>())
                {
                    DirectoryInfo source = new DirectoryInfo(item.pth);
                    string fldname = new DirectoryInfo(item.pth).Name;
                    DirectoryInfo target = new DirectoryInfo(ddlDrives.SelectedItem + "DataHistory\\" + fldname + "\\");

                    var bkpthread = new Thread(CopyDirectory(source.ToString(), target.ToString()))
                    {
                        IsBackground = true
                    };
                    bkpthread.Start();

                    //CopyDirectory(source.ToString(),target.ToString());
                }
            }
            else
            {
                ChkDest();
            }
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ddlDrives.SelectedItem.ToString().Contains("C"))
            {
                FlashTB.Visibility = Visibility.Visible;
                tblk1.Visibility = Visibility.Visible;
            }
            else
            {
                FlashTB.Visibility = Visibility.Hidden;
                tblk1.Visibility = Visibility.Hidden;
            }
        }
        public void CopyDirectory(string SourceDirectory, string TargetDirectory)
        {
            string ErrorLog = "c:\\temp\\log.txt";
            DirectoryInfo source = new DirectoryInfo(SourceDirectory);
            DirectoryInfo target = new DirectoryInfo(TargetDirectory);

            //Determine whether the source directory exists.
            try
            {
                if (!source.Exists)
                    return;
                if (!target.Exists)
                    Directory.CreateDirectory(target.FullName);
            }
            catch (IOException errorCreate)
            {
                using (StreamWriter writer = new StreamWriter(ErrorLog))
                {
                    writer.WriteLine(errorCreate.Message);
                }
            }

            //Copy files.
            try
            {
                FileInfo[] sourceFiles = source.GetFiles();
                for (int i = 0; i < sourceFiles.Length; ++i)
                    File.Copy(sourceFiles[i].FullName, target.FullName + "\\" + sourceFiles[i].Name, true);
            }
            catch (IOException copyError)
            {
                using (StreamWriter writer = new StreamWriter(ErrorLog))
                {
                    writer.WriteLine(copyError.Message);
                }
            }

            //Copy directories.
            try
            {
                DirectoryInfo[] sourceDirectories = source.GetDirectories();
                for (int j = 0; j < sourceDirectories.Length; ++j)
                    CopyDirectory(sourceDirectories[j].FullName, target.FullName + "\\" + sourceDirectories[j].Name);
            }
            catch (IOException errorDir)
            {
                using (StreamWriter writer = new StreamWriter(ErrorLog))
                {
                    writer.WriteLine(errorDir.Message);
                }
            }
        }
    }
}

AnswerRe: Multi threading in C# Pin
JudyL_MD28-May-20 10:45
JudyL_MD28-May-20 10:45 
AnswerRe: Multi threading in C# Pin
F-ES Sitecore29-May-20 1:17
professionalF-ES Sitecore29-May-20 1:17 
GeneralRe: Multi threading in C# Pin
bjwaldo30-May-20 7:30
bjwaldo30-May-20 7:30 
QuestionLinq TO SQL - Pass Table Name Pin
Kevin Marois28-May-20 8:57
professionalKevin Marois28-May-20 8:57 
AnswerRe: Linq TO SQL - Pass Table Name Pin
Richard Deeming29-May-20 0:11
mveRichard Deeming29-May-20 0:11 
QuestionC# How To Get Version Info Of exe in FTP Pin
Ertuğrul ÇİÇEK28-May-20 3:16
Ertuğrul ÇİÇEK28-May-20 3:16 
AnswerRe: C# How To Get Version Info Of exe in FTP Pin
Richard MacCutchan28-May-20 3:19
mveRichard MacCutchan28-May-20 3:19 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Ertuğrul ÇİÇEK28-May-20 3:41
Ertuğrul ÇİÇEK28-May-20 3:41 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Richard MacCutchan28-May-20 3:43
mveRichard MacCutchan28-May-20 3:43 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Richard Deeming28-May-20 3:53
mveRichard Deeming28-May-20 3:53 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
OriginalGriff28-May-20 3:57
mveOriginalGriff28-May-20 3:57 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Ertuğrul ÇİÇEK28-May-20 6:32
Ertuğrul ÇİÇEK28-May-20 6:32 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Richard Deeming28-May-20 8:32
mveRichard Deeming28-May-20 8:32 
QuestionCreating and Binding UI objects in C# instead of XAML (WPF) Pin
Member 1484454026-May-20 12:04
Member 1484454026-May-20 12:04 
AnswerRe: Creating and Binding UI objects in C# instead of XAML (WPF) Pin
Mycroft Holmes26-May-20 12:26
professionalMycroft Holmes26-May-20 12:26 
AnswerRe: Creating and Binding UI objects in C# instead of XAML (WPF) Pin
Richard Deeming27-May-20 1:01
mveRichard Deeming27-May-20 1:01 
QuestionHow to mount an ISO file with disc type - CD/DVD Pin
Member 1001484126-May-20 6:43
Member 1001484126-May-20 6:43 

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.