darshanbihani says:
while
(
true
)
{
Why are you using while loop?
Remove the while loop that causes the infinite loop.
Here is the modified code.
public DataSet ProcessCustomerWithBills()
{
try
{
bool anyCustomerWithBills = false; // Declare the flag outside the loop
// Retrieve customer ID with bills
List<string> customerIds = CustomerHasBills();
// If no customer with bills found, return null
if (customerIds == null || customerIds.Count == 0)
{
return;
}
foreach (string customerId in customerIds)
{
// Further process the customer ID (e.g., generate report)
paraname.Clear();
paravalue.Clear();
ds.Clear();
paraname.Add("@TTo");
paravalue.Add(customerId.Trim());
// Further process the customer ID (e.g., generate report)
paraname.Add("@flag");
paravalue.Add("OK");
ds = bl_obj.getdata_WithParavalue(paraname, paravalue, "SP_DC_Reverse");
// If data is found for the customer, return the report data
if (ds.Tables[0].Rows.Count > 0)
{
byte[] reportBytes = GenerateExcelReport(ds);
// Send Email with Excel attachment
SendEmailWithAttachment(reportBytes);
anyCustomerWithBills = true;
// return ds;
}
// If no data found for the customer, continue looping to check next customer
}
if (anyCustomerWithBills)
{
return null;
}
}
catch (Exception ex)
{
// Handle exception
throw new Exception("Error processing customer with bills: " + ex.Message);
}
}