SlideShare uma empresa Scribd logo
1 de 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Objectives
In this lesson, you will learn to:
Identify the benefits of the .NET System.IO model
Identify the benefits of the Visual Basic .NET run-time
functions
Identify the benefits of multithreading
Implement threads in Visual Basic .NET




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                Slide 1 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
File
Is a collection of bytes that has a persistent storage.
I/O operations in Visual Basic .NET are handled in two
different ways:
         Using the .NET System.IO model
         Using the Visual Basic .NET run-time functions




©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                  Slide 2 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
System.IO Model
Specifies a set of classes that are available to all the .NET
     languages.
Contains classes that are used for creating, copying,
moving, and deleting files.
Contains the following frequently used classes:
         FileStream
         BinaryReader and BinaryWriter
         StreamReader and StreamWriter
         Directory


©NIIT    Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                 Slide 3 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
The File Hierarchy in the System.IO Model




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                Slide 4 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
The FileStream Class
Provides access to files and file-related information.
Is used with the File class, which is contained in the
System.IO namespace, to create, copy, delete, move, and
      open files.
Can also be used with another class called Path, to
manipulate the strings that represent folder or file paths.
Opens a file either in synchronous or asynchronous mode.
Opens files in synchronous mode by default.
Has constructors that use enumerations, such as FileMode,
       FileAccess, and FileShare, to specify how a file is
created,      opened, and shared.
©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                Slide 5 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
FileMode Enumerations
                    Members                                        Description



  Append                                          It is used to open a file if it exists and move
                                                  the file pointer to the end of the file, or
                                                  create a new file. Append can only be used
                                                  with the FileAccess.Write.


  Create                                          It is used to specify that the operating
                                                  system should create a new file. However,
                                                  if the file already exists, it will be
                                                  overwritten.

  CreateNew                                       It is used to specify that the operating
                                                  system should create a new file. However,
                                                  if the file already exists, it will throw an
                                                  exception.




©NIIT      Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                   Slide 6 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
FileMode Enumerations (Contd.)
                       Members                                      Description


        Open                                        It is used to specify that the operating
                                                    system should open an existing file.




        OpenOrCreate                                It is used to specify that the operating
                                                    system should open an existing file.
                                                    However, if the file does not exist, a new
                                                    file should be created.



        Truncate                                    It is used to specify that the operating
                                                    system should open an existing file. After
                                                    the file is opened, the file should be
                                                    truncated so that its size is zero bytes.




©NIIT       Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                    Slide 7 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
FileAccess Enumerations
                   Members                                        Description



  Read                                           It is used to specify Read access to a file so
                                                 that data can be read from the file.



  ReadWrite                                      It is used to specify Read and Write access
                                                 to a file so that data can be written to and
                                                 read from the file.


  Write                                          It is used to specify Write access to a file so
                                                 that data can be written to the file.




©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                  Slide 8 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
FileShare Enumerations
                   Members                                         Description


  None                                           It is used to decline sharing of the current
                                                 file. When this constant is used with the
                                                 FileShare enumeration, a request to open the
                                                 file will fail until the file is closed.
  Read                                           It is used to allow subsequent opening of a
                                                 file for reading. If this flag is not used, a
                                                 request to open the file for reading will fail
                                                 until the file is closed.
  ReadWrite                                      It is used to allow subsequent opening of a
                                                 file for reading or writing. If this flag is not
                                                 used, any request to open the file for writing
                                                 or reading will fail until the file is closed.

  Write                                          It is used to allow subsequent opening of a
                                                 file for writing. If this flag is not used, any
                                                 request to open the file for writing will fail
                                                 until the file is closed.

©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                  Slide 9 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
BinaryReader and BinaryWriter Classes
Are used to read from and write to a binary file.

StreamReader and StreamWriter Classes
Are used to read and write data as streams of
characters.
Use specific encoding to convert characters to and from
bytes.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 10 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
The Directory Class
Enables you to work with drives and folders.
                    Method                                       Usage


        CreateDirectory()                  It is used to create the directories specified by
                                           a path.




        Delete()                           It is used to delete a directory and all its
                                           contents.



        Exists()                           It is used to determine whether the specified
                                           path refers to an existing directory on the disk.




©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                 Slide 11 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Directory Class (Contd.)

                    Method                                        Usage


        GetDirectoryRoot()                  It is used to return the root portion of a
                                            specified path.




        GetLogicalDrives()                  It is used to retrieve the names of the logical
                                            drives on the current computer.



        Move()                              It is used to move a directory and its contents
                                            to a new path.




©NIIT       Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                   Slide 12 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Just a Minute…
2. The code snippet generates a build error. Identify the error.
3. What is the difference between the CreateNew and Create
   constants of the FileMode enumeration?
4. Complete the code to ensure that the file Product.txt is
   opened with no share specification.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 13 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Visual Basic .NET Run-time Functions
Provide compatibility with earlier versions of Visual Basic.
Allow three types of file access:
         Sequential
         Random
         Binary
Are defined in the System.IO.File namespace.




©NIIT    Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                Slide 14 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Functions Used to Access Files
 Dir – It is used to retrieve the name of a file or directory that
  matches a specific pattern based on the file attribute or
  volume label of a file.
 EOF – It is used to check whether the end of the file is
  reached. When a file is opened for random or sequential
  access, if the end of the file is reached, the function returns
  a Boolean value True.
 FileCopy – It is used to create a copy of an existing file.
 FileDateTime – It is used to retrieve the date and time when
  a file was created or last modified.
 FileLen – It is used to retrieve the length of a file in bytes.

©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 15 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Functions Used to Access Files (Contd.)
FreeFile – It is used to retrieve the next file number
available for use by the FileOpen() function.
GetAttr – It is used to retrieve a FileAttribute value
representing the attributes of a file or directory.
Loc – It is used to retrieve a value specifying the current
read/write position within an open file.
LOF – It is used to retrieve a value representing the size, in
     bytes, of a file opened using the FileOpen()function.
Seek – It is used to retrieve a value specifying the current
       read/write position within a file opened using the
FileOpen()function or sets the position for the next
read/write operation within a file opened using the
FileOpen() function.
SetAttr – It sets the attribute information for a file.
©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 16 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Functions Used to Access Data from a File
With sequential access, a file can be opened in the Input,
        Output, or Append mode. In the Input mode, a file is
opened          for reading data from the file. In the Output or
Append          mode, a file is opened for writing data to the
file. The syntax        for using the FileOpen() function with
sequential access       is as follows:
     FileOpen(FileNumber, FileName,
OpenMode.mode   type)




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 17 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Functions Used to Access Data from a File (Contd.)
With random access, the FileOpen() function is used to
        read and write data to a file without closing the file.
Random-access files store data in records, which makes it
easy to locate relevant information quickly. The syntax for
using the FileOpen() function with random access is as
follows:
FileOpen(FileNumber, FileName,
OpenMode.Random,OpenAccess=OpenAccess.Default,
OpenShare=OpenShare.Default,RecordLength=
length of the record)




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 18 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Functions Used to Access Data from a File (Contd.)
With binary access, the FileOpen() function is used to
      read or write to any byte position in a file. The syntax
for   using the FileOpen()function with binary access is
as    follows:
     FileOpen(FileNumber, FileName,
OpenMode.Binary)




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 19 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Functions Used to Write Data to and Read Data From
Files

             Access type            Functions for writing      Functions for reading
                                           data                        data


        Sequential                Print, PrintLine            Input, InputString



        Random                    FilePut                     FileGet



        Binary                    FilePut                     FileGet




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 20 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Just a Minute…
Complete the code to display the contents of the file named
Product.txt in the output window.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 21 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Problem Statement 10.D.1
The users at the call centers of Diaz Telecommunications
should be able to create a text file for storing customer
feedback on the services provided by Diaz
Telecommunications. The users should also be able to open
the file for future assessment.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 22 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Task List
Identify the mechanism to implement the user requirement.
Identify the controls needed to provide the user interface.
Perform the appropriate steps to design the form.
Write the code to implement the identified mechanism.
Save the application.
Run the application to validate the conditions applied on the
      form.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 23 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Task 1: Identify the mechanism to implement the
user requirement.
Result:
 You can fulfill the user requirement by using either the
classes in the System.IO model or the Visual Basic .NET
run-time functions. However, since the System.IO model is
a part of the .NET Framework class library, you should
implement the relevant classes of the System.IO model to
   make full use of the .NET Framework features of Visual
Basic .NET.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 24 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Task 2: Identify the controls needed to provide the
user interface.
Result:
As per the plan, you need to add a RichTextBox control, a
      label control, and two buttons, Read Data and Write
Data, to the form named frmCustomerFeedback.
In addition, a Reset button should be used to clear the
contents of the RichTextBox control.
To ensure that data is first written and then read from the
      file, initially the Read Data button will be disabled. To
clear the contents of the RichTextBox, the Reset button will
be    used.


©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 25 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Task 3: Perform the appropriate steps to design the
form.
Task 4: Write the code to implement the identified
mechanism.
Task 5: Save the application.
Task 6: Run the application to validate the conditions
applied on the form.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 26 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Problem Statement 10.P.1
The users at the call centers of Diaz Telecommunications
should be able to create a text file for storing product details
that are available for sale. The users should be able to read
from or write data to the file as a sequence of characters. The
users should also be able to open the file for future
assessment.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 27 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Threads
Help in performing multiple activities simultaneously.


MultiThreading
Is a process in which individual activities are executed on
 separate threads.
Is also called free threading in Visual Basic .NET.
Enables you to create scalable applications since you can
 add threads to an application as the workload increases.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 28 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Creating a Thread
Requires declaring a variable of the System.Threading.
      Thread class and calling the constructor of the thread
class with the AddressOf operator and the name of the
procedure you want to execute on the new thread.
          Example
     Dim MyThread As New
System.Threading.Thread(AddressOf MySub)
Starting Execution of a Thread
You can start a thread by using the Start()method.
Stopping Execution of a Thread
You can stop the execution of a thread by calling the
Abort()method.
©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 29 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Thread Priorities
Are defined by using the Priority property.
By default set to Normal.
Can be changed by using the ThreadPriority
enumeration.
                    Values                                      Description

    AboveNormal                                 Specifies that the thread has a higher
                                                priority than Normal

    BelowNormal                                 Specifies that the thread has the lower
                                                priority
    Highest                                     Specifies that the thread has the highest
                                                priority
    Lowest                                      Specifies that the thread has the lowest
                                                priority
    Normal                                      Specifies that the thread has an average
                                                priority
©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 30 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Thread State
Is accessed by using the ThreadState property.
Can be a combination of the values in the
System.Threading.Threadstate enumeration, that is,
     a thread can be in more than one state at a given time.
Can be changed by the following methods:
         Thread.Sleep()
         Thread.Suspend()
         Thread.Interrupt()
         Thread.Resume()
         Thread.Abort()
©NIIT    Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                Slide 31 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Thread Lifecycle
Starts when an object of the System.Threading.Thread
        class is created and stops when any of the following
occurs:
         The method the thread is running completes
         The process containing the thread terminates
         The Abort() method is called for the thread object




©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                 Slide 32 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Thread Lifecycle (Contd.)
The following diagram illustrates the thread states and the
       methods that would cause the thread to leave each
state.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 33 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Multithreaded Procedures
Can accept arguments.
Can return values.

Thread Synchronization
Is done by using events in an application.
The SyncLock Statement
Ensures that multiple threads do not access shared data at
     the same time.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 34 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Just a Minute…
There is a class called CalcClass, which has a Sub
procedure called CalculateArea(). You need to execute
this procedure in a separate thread. To execute the
CalculateArea() procedure, you need to declare a
variable of the thread type. Complete the declaration of the
variable in the code snippet.




©NIIT   Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                               Slide 35 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Summary
In this lesson, you learned that:
The file I/O operations in Visual Basic .NET can be done in
      two different ways:
         Using the .NET System.IO model
         Using the Visual Basic .NET run-time functions
The System.IO model specifies the use of the common
classes available to all the .NET languages.
The classes in the System.IO namespace that are mostly
      used are:
         FileStream
         BinaryReader

©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                 Slide 36 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Summary (Contd.)
         BinaryWriter
         StreamReader
         StreamWriter
         Directory
Visual Basic .NET run-time functions allow three types of file
      access:
         Sequential
         Random
         Binary
Threads can be implemented in Visual Basic by declaring a
     variable of the System.Threading.Thread type.
©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                 Slide 37 of 38
Performing File I/O Operations and Implementing
Multithreading in Visual Basic .NET
Summary (Contd.)
The methods that are mostly used to manipulate a thread
     are:
         Start()
         Sleep()
         Suspend()
         Resume()
         Abort()




©NIIT     Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/
                                                                                 Slide 38 of 38

Mais conteúdo relacionado

Mais procurados

Java session01
Java session01Java session01
Java session01Niit Care
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01Niit Care
 
Icnd210 sg vol 2
Icnd210 sg vol 2Icnd210 sg vol 2
Icnd210 sg vol 2Fer Rosas
 
Cso gaddis java_chapter7
Cso gaddis java_chapter7Cso gaddis java_chapter7
Cso gaddis java_chapter7mlrbrown
 
Training report anish
Training report anishTraining report anish
Training report anishAnish Yadav
 
Application Development | Delphi Review 2009
Application Development | Delphi Review 2009Application Development | Delphi Review 2009
Application Development | Delphi Review 2009Michael Findling
 
3 f6 8_databases
3 f6 8_databases3 f6 8_databases
3 f6 8_databasesop205
 
Chapter 2 slides
Chapter 2 slidesChapter 2 slides
Chapter 2 slideslara_ays
 
3 f6 9_distributed_systems
3 f6 9_distributed_systems3 f6 9_distributed_systems
3 f6 9_distributed_systemsop205
 
Dot Net Interview Questions - Part 1
Dot Net Interview Questions - Part 1Dot Net Interview Questions - Part 1
Dot Net Interview Questions - Part 1ReKruiTIn.com
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overviewQA Club Kiev
 
Alliance Successful Selenium Automation
Alliance Successful Selenium AutomationAlliance Successful Selenium Automation
Alliance Successful Selenium Automationsadams22
 
Build Community Android Distribution and Ensure the Quality
Build Community Android Distribution and Ensure the QualityBuild Community Android Distribution and Ensure the Quality
Build Community Android Distribution and Ensure the QualityNational Cheng Kung University
 
.Net framework interview questions
.Net framework interview questions.Net framework interview questions
.Net framework interview questionsMir Majid
 

Mais procurados (20)

Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Java session01
Java session01Java session01
Java session01
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01
 
Icnd210 sg vol 2
Icnd210 sg vol 2Icnd210 sg vol 2
Icnd210 sg vol 2
 
Cso gaddis java_chapter7
Cso gaddis java_chapter7Cso gaddis java_chapter7
Cso gaddis java_chapter7
 
Training report anish
Training report anishTraining report anish
Training report anish
 
Application Development | Delphi Review 2009
Application Development | Delphi Review 2009Application Development | Delphi Review 2009
Application Development | Delphi Review 2009
 
3 f6 8_databases
3 f6 8_databases3 f6 8_databases
3 f6 8_databases
 
Chapter 2 slides
Chapter 2 slidesChapter 2 slides
Chapter 2 slides
 
Unit 01 - Introduction
Unit 01 - IntroductionUnit 01 - Introduction
Unit 01 - Introduction
 
3 f6 9_distributed_systems
3 f6 9_distributed_systems3 f6 9_distributed_systems
3 f6 9_distributed_systems
 
Dot Net Interview Questions - Part 1
Dot Net Interview Questions - Part 1Dot Net Interview Questions - Part 1
Dot Net Interview Questions - Part 1
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overview
 
Documentation
DocumentationDocumentation
Documentation
 
Core java part1
Core java  part1Core java  part1
Core java part1
 
Alliance Successful Selenium Automation
Alliance Successful Selenium AutomationAlliance Successful Selenium Automation
Alliance Successful Selenium Automation
 
Build Community Android Distribution and Ensure the Quality
Build Community Android Distribution and Ensure the QualityBuild Community Android Distribution and Ensure the Quality
Build Community Android Distribution and Ensure the Quality
 
.Net framework interview questions
.Net framework interview questions.Net framework interview questions
.Net framework interview questions
 

Destaque

File handling in vb.net
File handling in vb.netFile handling in vb.net
File handling in vb.netEverywhere
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET FrameworkLearnNowOnline
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1Vijay Perepa
 
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)Mohamed Saleh
 
Improving The Software Development Lifecycle With Visual Studio Team System
Improving The Software Development Lifecycle With Visual Studio Team SystemImproving The Software Development Lifecycle With Visual Studio Team System
Improving The Software Development Lifecycle With Visual Studio Team Systemmatthewphillips
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewYuki Anzai
 
The visual elements of an image (english version)
The visual elements of an image (english version)The visual elements of an image (english version)
The visual elements of an image (english version)LARIBERAPLASTICA
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NETrchakra
 
Classification of Hand Tools - PART 1
Classification of Hand Tools - PART 1Classification of Hand Tools - PART 1
Classification of Hand Tools - PART 1Pilita Santos
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 

Destaque (20)

File handling
File handlingFile handling
File handling
 
File handling in vb.net
File handling in vb.netFile handling in vb.net
File handling in vb.net
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET Framework
 
eSocial - Plano de Voo Vilesoft
eSocial - Plano de Voo VilesofteSocial - Plano de Voo Vilesoft
eSocial - Plano de Voo Vilesoft
 
Intake 37 11
Intake 37 11Intake 37 11
Intake 37 11
 
Listview
ListviewListview
Listview
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1
 
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
Module 4: Introduction to ASP.NET 3.5 (PowerPoint Slides)
 
Filehandling
FilehandlingFilehandling
Filehandling
 
Improving The Software Development Lifecycle With Visual Studio Team System
Improving The Software Development Lifecycle With Visual Studio Team SystemImproving The Software Development Lifecycle With Visual Studio Team System
Improving The Software Development Lifecycle With Visual Studio Team System
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
 
dotNetMálaga - Taller Xamarin
dotNetMálaga - Taller XamarindotNetMálaga - Taller Xamarin
dotNetMálaga - Taller Xamarin
 
The visual elements of an image (english version)
The visual elements of an image (english version)The visual elements of an image (english version)
The visual elements of an image (english version)
 
Microsoft visual basic 6
Microsoft visual basic 6Microsoft visual basic 6
Microsoft visual basic 6
 
The Best Source Code VB
The Best Source Code VBThe Best Source Code VB
The Best Source Code VB
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
Classification of Hand Tools - PART 1
Classification of Hand Tools - PART 1Classification of Hand Tools - PART 1
Classification of Hand Tools - PART 1
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 

Semelhante a Vb net xp_10

Deployment with ExpressionEngine
Deployment with ExpressionEngineDeployment with ExpressionEngine
Deployment with ExpressionEngineGreen Egg Media
 
Laporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdf
Laporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdfLaporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdf
Laporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdfIGedeArieYogantaraSu
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingChereLemma2
 
Union FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerUnion FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerKnoldus Inc.
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...mfrancis
 
USING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNED
USING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNEDUSING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNED
USING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNEDijseajournal
 
Multidiscipline Collaboration On A Single Central File
Multidiscipline Collaboration On A Single Central FileMultidiscipline Collaboration On A Single Central File
Multidiscipline Collaboration On A Single Central Filejowett9
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
Hibernate reference1
Hibernate reference1Hibernate reference1
Hibernate reference1chandra mouli
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaEdureka!
 

Semelhante a Vb net xp_10 (20)

Ex11 mini project
Ex11 mini projectEx11 mini project
Ex11 mini project
 
Deployment with ExpressionEngine
Deployment with ExpressionEngineDeployment with ExpressionEngine
Deployment with ExpressionEngine
 
Laporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdf
Laporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdfLaporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdf
Laporan Praktikum Keamanan Siber - Tugas 3 - Kelas C - Kelompok 3.pdf
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
 
Selenium Training in Chennai
Selenium Training in ChennaiSelenium Training in Chennai
Selenium Training in Chennai
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
J threads-pdf
J threads-pdfJ threads-pdf
J threads-pdf
 
Union FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerUnion FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a Container
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
 
USING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNED
USING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNEDUSING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNED
USING JUPYTERHUB IN THE CLASSROOM: SETUP AND LESSONS LEARNED
 
Multidiscipline Collaboration On A Single Central File
Multidiscipline Collaboration On A Single Central FileMultidiscipline Collaboration On A Single Central File
Multidiscipline Collaboration On A Single Central File
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Hibernate reference1
Hibernate reference1Hibernate reference1
Hibernate reference1
 
File operations
File operationsFile operations
File operations
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | Edureka
 
Mc7404 np final
Mc7404 np finalMc7404 np final
Mc7404 np final
 

Mais de Niit Care

Mais de Niit Care (19)

Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 
Dacj 1-3 b
Dacj 1-3 bDacj 1-3 b
Dacj 1-3 b
 
Dacj 1-3 a
Dacj 1-3 aDacj 1-3 a
Dacj 1-3 a
 
Dacj 1-2 c
Dacj 1-2 cDacj 1-2 c
Dacj 1-2 c
 
Dacj 1-2 a
Dacj 1-2 aDacj 1-2 a
Dacj 1-2 a
 
Dacj 1-1 c
Dacj 1-1 cDacj 1-1 c
Dacj 1-1 c
 
Dacj 1-1 b
Dacj 1-1 bDacj 1-1 b
Dacj 1-1 b
 
Dacj 1-1 a
Dacj 1-1 aDacj 1-1 a
Dacj 1-1 a
 
Dacj 2-2 b
Dacj 2-2 bDacj 2-2 b
Dacj 2-2 b
 
Dacj 2-2 a
Dacj 2-2 aDacj 2-2 a
Dacj 2-2 a
 
Dacj 2-1 c
Dacj 2-1 cDacj 2-1 c
Dacj 2-1 c
 

Último

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Vb net xp_10

  • 1. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Objectives In this lesson, you will learn to: Identify the benefits of the .NET System.IO model Identify the benefits of the Visual Basic .NET run-time functions Identify the benefits of multithreading Implement threads in Visual Basic .NET ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 1 of 38
  • 2. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET File Is a collection of bytes that has a persistent storage. I/O operations in Visual Basic .NET are handled in two different ways: Using the .NET System.IO model Using the Visual Basic .NET run-time functions ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 2 of 38
  • 3. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET System.IO Model Specifies a set of classes that are available to all the .NET languages. Contains classes that are used for creating, copying, moving, and deleting files. Contains the following frequently used classes: FileStream BinaryReader and BinaryWriter StreamReader and StreamWriter Directory ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 3 of 38
  • 4. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET The File Hierarchy in the System.IO Model ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 4 of 38
  • 5. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET The FileStream Class Provides access to files and file-related information. Is used with the File class, which is contained in the System.IO namespace, to create, copy, delete, move, and open files. Can also be used with another class called Path, to manipulate the strings that represent folder or file paths. Opens a file either in synchronous or asynchronous mode. Opens files in synchronous mode by default. Has constructors that use enumerations, such as FileMode, FileAccess, and FileShare, to specify how a file is created, opened, and shared. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 5 of 38
  • 6. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET FileMode Enumerations Members Description Append It is used to open a file if it exists and move the file pointer to the end of the file, or create a new file. Append can only be used with the FileAccess.Write. Create It is used to specify that the operating system should create a new file. However, if the file already exists, it will be overwritten. CreateNew It is used to specify that the operating system should create a new file. However, if the file already exists, it will throw an exception. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 6 of 38
  • 7. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET FileMode Enumerations (Contd.) Members Description Open It is used to specify that the operating system should open an existing file. OpenOrCreate It is used to specify that the operating system should open an existing file. However, if the file does not exist, a new file should be created. Truncate It is used to specify that the operating system should open an existing file. After the file is opened, the file should be truncated so that its size is zero bytes. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 7 of 38
  • 8. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET FileAccess Enumerations Members Description Read It is used to specify Read access to a file so that data can be read from the file. ReadWrite It is used to specify Read and Write access to a file so that data can be written to and read from the file. Write It is used to specify Write access to a file so that data can be written to the file. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 8 of 38
  • 9. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET FileShare Enumerations Members Description None It is used to decline sharing of the current file. When this constant is used with the FileShare enumeration, a request to open the file will fail until the file is closed. Read It is used to allow subsequent opening of a file for reading. If this flag is not used, a request to open the file for reading will fail until the file is closed. ReadWrite It is used to allow subsequent opening of a file for reading or writing. If this flag is not used, any request to open the file for writing or reading will fail until the file is closed. Write It is used to allow subsequent opening of a file for writing. If this flag is not used, any request to open the file for writing will fail until the file is closed. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 9 of 38
  • 10. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET BinaryReader and BinaryWriter Classes Are used to read from and write to a binary file. StreamReader and StreamWriter Classes Are used to read and write data as streams of characters. Use specific encoding to convert characters to and from bytes. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 10 of 38
  • 11. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET The Directory Class Enables you to work with drives and folders. Method Usage CreateDirectory() It is used to create the directories specified by a path. Delete() It is used to delete a directory and all its contents. Exists() It is used to determine whether the specified path refers to an existing directory on the disk. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 11 of 38
  • 12. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Directory Class (Contd.) Method Usage GetDirectoryRoot() It is used to return the root portion of a specified path. GetLogicalDrives() It is used to retrieve the names of the logical drives on the current computer. Move() It is used to move a directory and its contents to a new path. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 12 of 38
  • 13. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Just a Minute… 2. The code snippet generates a build error. Identify the error. 3. What is the difference between the CreateNew and Create constants of the FileMode enumeration? 4. Complete the code to ensure that the file Product.txt is opened with no share specification. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 13 of 38
  • 14. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Visual Basic .NET Run-time Functions Provide compatibility with earlier versions of Visual Basic. Allow three types of file access: Sequential Random Binary Are defined in the System.IO.File namespace. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 14 of 38
  • 15. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Functions Used to Access Files Dir – It is used to retrieve the name of a file or directory that matches a specific pattern based on the file attribute or volume label of a file. EOF – It is used to check whether the end of the file is reached. When a file is opened for random or sequential access, if the end of the file is reached, the function returns a Boolean value True. FileCopy – It is used to create a copy of an existing file. FileDateTime – It is used to retrieve the date and time when a file was created or last modified. FileLen – It is used to retrieve the length of a file in bytes. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 15 of 38
  • 16. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Functions Used to Access Files (Contd.) FreeFile – It is used to retrieve the next file number available for use by the FileOpen() function. GetAttr – It is used to retrieve a FileAttribute value representing the attributes of a file or directory. Loc – It is used to retrieve a value specifying the current read/write position within an open file. LOF – It is used to retrieve a value representing the size, in bytes, of a file opened using the FileOpen()function. Seek – It is used to retrieve a value specifying the current read/write position within a file opened using the FileOpen()function or sets the position for the next read/write operation within a file opened using the FileOpen() function. SetAttr – It sets the attribute information for a file. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 16 of 38
  • 17. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Functions Used to Access Data from a File With sequential access, a file can be opened in the Input, Output, or Append mode. In the Input mode, a file is opened for reading data from the file. In the Output or Append mode, a file is opened for writing data to the file. The syntax for using the FileOpen() function with sequential access is as follows: FileOpen(FileNumber, FileName, OpenMode.mode type) ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 17 of 38
  • 18. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Functions Used to Access Data from a File (Contd.) With random access, the FileOpen() function is used to read and write data to a file without closing the file. Random-access files store data in records, which makes it easy to locate relevant information quickly. The syntax for using the FileOpen() function with random access is as follows: FileOpen(FileNumber, FileName, OpenMode.Random,OpenAccess=OpenAccess.Default, OpenShare=OpenShare.Default,RecordLength= length of the record) ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 18 of 38
  • 19. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Functions Used to Access Data from a File (Contd.) With binary access, the FileOpen() function is used to read or write to any byte position in a file. The syntax for using the FileOpen()function with binary access is as follows: FileOpen(FileNumber, FileName, OpenMode.Binary) ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 19 of 38
  • 20. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Functions Used to Write Data to and Read Data From Files Access type Functions for writing Functions for reading data data Sequential Print, PrintLine Input, InputString Random FilePut FileGet Binary FilePut FileGet ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 20 of 38
  • 21. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Just a Minute… Complete the code to display the contents of the file named Product.txt in the output window. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 21 of 38
  • 22. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Problem Statement 10.D.1 The users at the call centers of Diaz Telecommunications should be able to create a text file for storing customer feedback on the services provided by Diaz Telecommunications. The users should also be able to open the file for future assessment. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 22 of 38
  • 23. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Task List Identify the mechanism to implement the user requirement. Identify the controls needed to provide the user interface. Perform the appropriate steps to design the form. Write the code to implement the identified mechanism. Save the application. Run the application to validate the conditions applied on the form. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 23 of 38
  • 24. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Task 1: Identify the mechanism to implement the user requirement. Result: You can fulfill the user requirement by using either the classes in the System.IO model or the Visual Basic .NET run-time functions. However, since the System.IO model is a part of the .NET Framework class library, you should implement the relevant classes of the System.IO model to make full use of the .NET Framework features of Visual Basic .NET. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 24 of 38
  • 25. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Task 2: Identify the controls needed to provide the user interface. Result: As per the plan, you need to add a RichTextBox control, a label control, and two buttons, Read Data and Write Data, to the form named frmCustomerFeedback. In addition, a Reset button should be used to clear the contents of the RichTextBox control. To ensure that data is first written and then read from the file, initially the Read Data button will be disabled. To clear the contents of the RichTextBox, the Reset button will be used. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 25 of 38
  • 26. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Task 3: Perform the appropriate steps to design the form. Task 4: Write the code to implement the identified mechanism. Task 5: Save the application. Task 6: Run the application to validate the conditions applied on the form. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 26 of 38
  • 27. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Problem Statement 10.P.1 The users at the call centers of Diaz Telecommunications should be able to create a text file for storing product details that are available for sale. The users should be able to read from or write data to the file as a sequence of characters. The users should also be able to open the file for future assessment. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 27 of 38
  • 28. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Threads Help in performing multiple activities simultaneously. MultiThreading Is a process in which individual activities are executed on separate threads. Is also called free threading in Visual Basic .NET. Enables you to create scalable applications since you can add threads to an application as the workload increases. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 28 of 38
  • 29. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Creating a Thread Requires declaring a variable of the System.Threading. Thread class and calling the constructor of the thread class with the AddressOf operator and the name of the procedure you want to execute on the new thread. Example Dim MyThread As New System.Threading.Thread(AddressOf MySub) Starting Execution of a Thread You can start a thread by using the Start()method. Stopping Execution of a Thread You can stop the execution of a thread by calling the Abort()method. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 29 of 38
  • 30. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Thread Priorities Are defined by using the Priority property. By default set to Normal. Can be changed by using the ThreadPriority enumeration. Values Description AboveNormal Specifies that the thread has a higher priority than Normal BelowNormal Specifies that the thread has the lower priority Highest Specifies that the thread has the highest priority Lowest Specifies that the thread has the lowest priority Normal Specifies that the thread has an average priority ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 30 of 38
  • 31. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Thread State Is accessed by using the ThreadState property. Can be a combination of the values in the System.Threading.Threadstate enumeration, that is, a thread can be in more than one state at a given time. Can be changed by the following methods: Thread.Sleep() Thread.Suspend() Thread.Interrupt() Thread.Resume() Thread.Abort() ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 31 of 38
  • 32. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Thread Lifecycle Starts when an object of the System.Threading.Thread class is created and stops when any of the following occurs: The method the thread is running completes The process containing the thread terminates The Abort() method is called for the thread object ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 32 of 38
  • 33. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Thread Lifecycle (Contd.) The following diagram illustrates the thread states and the methods that would cause the thread to leave each state. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 33 of 38
  • 34. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Multithreaded Procedures Can accept arguments. Can return values. Thread Synchronization Is done by using events in an application. The SyncLock Statement Ensures that multiple threads do not access shared data at the same time. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 34 of 38
  • 35. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Just a Minute… There is a class called CalcClass, which has a Sub procedure called CalculateArea(). You need to execute this procedure in a separate thread. To execute the CalculateArea() procedure, you need to declare a variable of the thread type. Complete the declaration of the variable in the code snippet. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 35 of 38
  • 36. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Summary In this lesson, you learned that: The file I/O operations in Visual Basic .NET can be done in two different ways: Using the .NET System.IO model Using the Visual Basic .NET run-time functions The System.IO model specifies the use of the common classes available to all the .NET languages. The classes in the System.IO namespace that are mostly used are: FileStream BinaryReader ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 36 of 38
  • 37. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Summary (Contd.) BinaryWriter StreamReader StreamWriter Directory Visual Basic .NET run-time functions allow three types of file access: Sequential Random Binary Threads can be implemented in Visual Basic by declaring a variable of the System.Threading.Thread type. ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 37 of 38
  • 38. Performing File I/O Operations and Implementing Multithreading in Visual Basic .NET Summary (Contd.) The methods that are mostly used to manipulate a thread are: Start() Sleep() Suspend() Resume() Abort() ©NIIT Performing File I/O Operations and Implementing Multithreading in VB .NET/Lesson 10/ Slide 38 of 38