Preheat oven to 350°F / 177°C. Spray an 11x7-inch baking dish (or any 2-quart casserole dish) with nonstick cooking spray.
Bring a large stockpot of well-salted water to a boil.
While the water is coming to a boil, prepare an ice bath by filling a large mixing bowl with ice water (about halfway full).
When water is boiling, add green beans and boil until bright green and tender, 5 to 6 minutes. Drain the beans and then transfer them to the ice bath to halt cooking. Set aside.
Place a large saute pan or skillet over medium heat. Add bacon and saute until crisp, 4 to 5 minutes. Transfer bacon to a paper towel-lined plate. Drain off all but a thin layer of bacon grease and return skillet to medium heat.
To bacon grease, add butter and then mushrooms. Saute until mushrooms are cooked down and very tender, 7 to 8 minutes. Stir in shallots and thyme leaves and saute for 2 minutes more.
Sprinkle salt, pepper, and flour over mushrooms and stir until no dry spots of flour remain.
Slowly pour in milk while whisking. Bring to a simmer and simmer until cream sauce has thickened, 5 to 6 minutes.
Drain green beans well.
Combine green beans, cream sauce, and ½ cup fried onions. Transfer to casserole dish.
Cover tightly with foil and bake until heated all the way through and bubbly, about 35 minutes. (Note: If the dish was made ahead and chilled, add an extra 15 to 20 minutes to the cook time to insure it is heated all the way through.)
Remove foil and top with bacon and ¾ cup fried onions.
Continue baking, uncovered, until golden brown on top, about 15 minutes more.