I am new in C#, I have one problem in my c# Windows Application. I am Created one windows application in c#, it is successfully working all the task, but when I am trying to open my c# windows application first time it requires approximately 1 minute and 30 seconds because one excel file is load in application when first time trying to open the application.
This excel file is use for "AutoCompleteStringCollection".
Please see the following code and suggest me solution how I can reduce time to my application Opening time.
private void Form1_Load(object sender, EventArgs e)
{
InitializeTextSearchListView();
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();
addItems(DataCollection,listView1);
textBox1.AutoCompleteCustomSource = DataCollection;
}
public void addItems(AutoCompleteStringCollection col, ListView ListView1)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
object missing = System.Reflection.Missing.Value;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open("C:\\SAM Files\\Static Ticker Data.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
if (!(((range.Cells[rCnt, cCnt] as Excel.Range).Value2) == null))
{
if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2.GetType().ToString() == "System.Double")
{
double d1 = (Double)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
str = Convert.ToString(d1);
col.Add(str);
}
else
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
col.Add(str);
}
}
}
}
Note: When I select less data contain excel then application opening time is also reduce means its problem for to select large data contain excel file.
So please tell me how I can reduce time to Open my Application.